Reputation: 21
I'm trying to write a tool in c# which will connect to Oracle database and I'm required to use ODBC.
If I use the following code:
using System.Data.Odbc;
string str1 = "DATA SOURCE=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=abcd.efgh.net)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service_name)));USER ID=user_id;PASSWORD=qassword";
OdbcConnection coon = new OdbcConnection();
coon.ConnectionString = str1;
coon.Open();
I get the error message:
An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in System.Data.dll
Additional information: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
even if I change the connection string to:
string str2 = "Driver={Oracle in OraClient12home1};DATA SOURCE=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=abcd.efgh.net)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service_name)));USER ID=user_id;PASSWORD=qassword";
I get the same error message. So I guess the problem is not the "Driver = {...}" part? But what did I get wrong in the "DATA SOURCE" part?
Thank you.
Upvotes: 1
Views: 10829
Reputation: 21
Try this
using System.Data.Odbc;
String connectionString = "Dsn=HP5ODBC;uid=system;pwd=manager";
OdbcConnection coon = new OdbcConnection();
coon.ConnectionString = connectionString;
coon.Open();
MessageBox.Show(coon.State.ToString());
Upvotes: 2
Reputation: 59557
Try
Driver={Oracle in OraClient12home1};DBQ={(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=abcd.efgh.net)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service_name)))};UID=user_id;PWD=qassword";
instead of
Driver={Oracle in OraClient12home1};DATA SOURCE=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=abcd.efgh.net)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service_name)));USER ID=user_id;PASSWORD=qassword";
See Using the Oracle ODBC Driver: Format of the Connection String and/or Oracle in OraClient11g_home1 connection strings
Upvotes: 0