8

I have written a program in C# to pull some data using OdbcConnection :

using System.Data.Odbc;
......

OdbcConnection OdbcConn = 
                new OdbcConnection(Properties.Settings.Default.ConnectionString);
OdbcCommand cmd = new OdbcCommand();

//open connection 
if (OdbcConn.State != ConnectionState.Open)
{
    OdbcConn.Open();
}

In my settings file, I have this ConnectionString:

Dsn=****;uid=userID;pwd=password

However I cannot establish a connection. I have an iseries access driver from IBM corp installed, but if I try MS access then I am able to connect. Any suggestions?

4444
  • 3,541
  • 10
  • 32
  • 43
saiful
  • 159
  • 1
  • 2
  • 5

3 Answers3

16

When in doubt (and it involves connections strings): http://www.connectionstrings.com/

James Hill
  • 60,353
  • 20
  • 145
  • 161
4

On a Windows 64 bit machine, make sure you check if your C# code is compiled in x86 (32-bit), x64, or "Any CPU". Note that if you compile as "Any CPU," it'll choose x64 bit drivers by default.

The 32-bit drivers can be found at C:\windows\SysWOW64\odbcad32.exe. The 32-bit drivers can be found at C:\windows\system32\odbcad32.exe.

First, make sure you verify your connection works with the ODBC Data Source Administrator using the paths I provided earlier. I.e. make a DSN and test it as Turbot suggested. Once you verified this connection works, your connection string can either use the DSN you just created or you can use a DSN free connection string.

For a quick reference, here is a sample of a DSN free connection string using a ODBC driver:

Driver={Progress OpenEdge 11.3 Driver};HOST=wfdscr11.wf.local;Port=1234;DB=MyDatabaseName;UID=John;PWD=Doe

In this example, I had to connect to a Progress database from my C# code and this is the connection string I used without having to specify a DSN. You can see below that the name of the driver is "Progress OpenEdge 11.3 Driver."

enter image description here

Eric Chhun
  • 191
  • 1
  • 4
0

I always like to verify the connection using Data source(ODBC) in control panel (assume you are in window environment). Make sure you see the drive available in your ODBC selection and follow the steps to test the connectivity.

as also mentioned above the connections strings website would give you idea what properties and format on which particular driver connectivity

Turbot
  • 5,095
  • 1
  • 22
  • 30