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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With