Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
Hi,

I have configured an ODBC connection to a SQL Server database using odbcad32 from SysWow64 folder. I am using 64 bit Windows 8 OS.

Now, I want to know how can I make a connection to the same database in c#.

Code snippets as example will be very helpful since I am a beginner here.

Thanks
Posted
Comments
Rahul Krishnan R 2-Sep-13 4:06am    
Hi,

Below is the code I tried to achieve the above.

private void MainForm_Load(object sender, EventArgs e)
{
string connetionString = null;
OdbcConnection cnn;
connetionString = "Data Provider=SQLOLEDB;Dsn=dsnname;Database=dbname;Uid=admin;Pwd=pwd";
cnn = new OdbcConnection(connetionString);
try
{
cnn.Open();
MessageBox.Show("Connection Open ! ");
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}



But getting an error message as shown below:

The Specified DSN contains an architecture mismatch between the driver and application.

I am working in a 64 bit PC.

Please shed some light on this...
Maarten Kools 2-Sep-13 4:35am    
Depends on the platform of your application, if it's a 32-bit application, then use the odbcad32 application from the SysWow64 folder. If your application is 64-bit, use the regular ODBC connection dialog from the Control Panel instead.
Rahul Krishnan R 2-Sep-13 7:13am    
I used the odbcad32 application from SysWow64 folder since my platform of the application is 64 bit and still no luck.
:(
Maarten Kools 2-Sep-13 8:04am    
Like I said in my previous comment, for 64-bit applications, use the regular version from the control panel instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900