Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include sid and port into an oracle connection string?

I would like to specify the port and sid in the connection string. After the following code runs

public static string ConnectionString
{
    get
    {
        string host = Config.CsHost;
        string sid = Config.CsSID;
        string port = Config.CsPort;
        string user = Config.CsUser;
        string pass = Config.CsPassword;
        return String.Format(@"Data Source = {0}:{1}\{2}; Persist Security Info = True; User Id = {3}; Password = {4}; Unicode = True", host, port, sid, user, pass);
    }
}

...

using (OracleConnection connection = new OracleConnection(ConnectionString))
{
    try
    {
        connection.Open();

the Open() doesn't respond... The problem is with the sid I think. What might be the problem?

UPDATE: I should use this kind of connection string. But I can't interpret it well.

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID))); User Id=myUsername;Password=myPassword;

Can someone help me interpret this?

like image 702
Mitulát báti Avatar asked Dec 31 '14 15:12

Mitulát báti


People also ask

What is SID in Oracle connection string?

A sid is the Site Identifier. It, plus the oracle_home, uniquely identify a database instance on a single machine. If you are on the machine with the database, you only need the oracle_sid and oracle_home to get connected directly.

What is Sid in DB connection?

Oracle SID is the unique name that uniquely identifies your instance/database where as Service name is the TNS alias that you give when you remotely connect to your database and this Service name is recorded in Tnsnames.

What is service name in Oracle connection string?

SERVICE_NAMES specifies one or more names by which clients can connect to the instance. The instance registers its service names with the listener. When a client requests a service, the listener determines which instances offer the requested service and routes the client to the appropriate instance.


1 Answers

I had to replace SERVICE_NAME to SID, so this:

return String.Format("SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1}))(CONNECT_DATA=(SID={2})));uid={3};pwd={4};", host, port, sid, user, pass);

did the trick.

like image 99
Mitulát báti Avatar answered Sep 21 '22 20:09

Mitulát báti