1

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.

Phil
  • 153
  • 5
  • 15
Wulala2006
  • 21
  • 2
  • 4
  • Have you configured the ODBC connection on the machine the application is running on? – Nathangrad Mar 24 '17 at 14:34
  • I tested the connection with ODBC Data Source Administrator, and the connection was successful. Is this what you mean? – Wulala2006 Mar 24 '17 at 14:54
  • https://www.connectionstrings.com/ – OldProgrammer Mar 24 '17 at 15:50
  • What is the architecture of your application, 32 bit (x86) or 64 bit (x64)? Is it the same as your Oracle client, resp. ODBC driver? – Wernfried Domscheit Mar 24 '17 at 18:23
  • It seems that the application (Visual Studio) us 32 bit..... Well, at least I have some clue to try out. Thank you. – Wulala2006 Mar 24 '17 at 20:19
  • Visual Studio is always 32 bit, but what did you set in compile options? – Wernfried Domscheit Mar 24 '17 at 21:35
  • I followed every step in this article: http://stackoverflow.com/questions/24104210/badimageformatexception-this-will-occur-when-running-in-64-bit-mode-with-the-32, hoping that 32-64-bit issue could be solved.But didn't work.. – Wulala2006 Mar 27 '17 at 19:53
  • I changed the driver to datadirect 7.1 oracle wire protocol, and that one worked. connection string = "DRIVER={DataDirect 7.1 Oracle Wire Protocol};HOST=server1;PORT=1522; UID=JOHN;PWD=XYZZY;SERVICENAME=SALES.US.ACME.COM" – Wulala2006 Mar 28 '17 at 19:28

2 Answers2

1

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());
Siddiqui
  • 11
  • 1
0

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

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110