Connecting to MYSQL error - c#

My code is wrote in C#
I have a problem while connecting to MYSQL remote DB .
The remote DB is 64 bit while the one in local system is 32bit.
The one in 32bit works, the one in remote doesn't.
Im using this version of drivers : " DRIVER={MySQL ODBC 5.3 ANSI Driver}; ", one in 32bit , the other one in 64bit (remote one)
This is the error i got :
System.Runtime.InteropServices.COMException (0x80004005):
[Microsoft][ODBC Driver Manager] Data source name not found and no
default driver specified
Anyone has any ideas to deal with this?
Thanks

Related

Postgresql odbc driver error c# [IM002] [Microsoft][ODBC Driver Manager] Data source name not found

I am setting up an database application to be database agnostic, and when testing with postgresql I get the standard dsn error:
[IM002] [Microsoft][ODBC Driver Manager] Data source name not found
I usually use SQL server and MySQL so I'm new to postgres, I tried the standard recommended Connection string:
"Driver = {PostgreSQL}; Server = localhost; Database = postgres; Port = 5432; Uid = postgres; Pwd = XXXXXX;"
I also tried the name of the odbc driver that I installed after installing postrgesql:
"Driver = {PostgreSQL ODBC Driver(UNICODE)}; Server = localhost; Database = postgres; Port = 5432; Uid = postgres; Pwd = XXXXXX;"
Setting up a DSN in odbc manager also works perfectly using the unicode driver, so I cant understand why i cant connect in my application, is there an error in the driver name that i am using in the connection string?
Your error message looks very strange. It tells about DSN not found. Are you sure you use connect string with Driver=...?
You can use ODBC connect string in several forms. At first you have created DSN, so you can use it:
DSN=mn_test; Uid=postgres; Pwd=postgres;
Then you can use other form of connect string:
Driver={PostgreSQL UNICODE};Server=127.0.0.1; Port=5493; Database=mn_test; Uid=postgres; Pwd=postgres;
Both work on my old 32 bit Windows environment. I test them with simple Python script (I use ActiveState Python in which there is simple odbc module):
import odbc
def test_odbc(connect_string):
print(connect_string)
db = odbc.odbc(connect_string)
c = db.cursor()
rs = c.execute("SELECT version()")
for txt in c.fetchall():
print('%s' % (txt[0]))
print('-----')
test_odbc('Driver={PostgreSQL UNICODE};Server=127.0.0.1; Port=5493; Database=mn_test; Uid=postgres; Pwd=postgres;')
test_odbc('DSN=mn_test; Uid=postgres; Pwd=postgres;')
When you created the DSN, did you create it with the correct odbcad tool? With the 64bit version found in C:\Windows\System32 if your application is 64bit and with the 32bit version found in C:\Windows\SysWOW64 if your application is 32bit?

Creating OdbcConnection to relativity client

I went through the process of creating the server and client ODBC objects in my computer to a Cobol database and I named the client PARSECCLI.
I tested the connection and it works. I can get datasets through Microsoft Query (I can't get Sql Server Management Studio to connect to it as a Linked Server or anything, but that's a separate question).
I can also create, through Visual Studio's wizard, a Datasource connection to it and the connection test succeeds. It creates this connection string:
Dsn=PARSECCLI;uid=.;codepage=1252
However, if I try to create an OdbcConnection to that string and open it - my end goal is to be able to run queries on the database and pull datasets from it - I get this:
System.Data.Odbc.OdbcException (0x80131937): ERROR [IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
if I take advice from This question and change my connection string to this:
OdbcConnection dbConnection = new OdbcConnection("DRIVER={Relativity Client};ServerName=192.168.0.109.1583;DSN=PARSECCLI;UID=.;codepage=1252"); //The local IP I set to static when I created the client and server odbc Data Sources.
I get:
System.Data.Odbc.OdbcException (0x80131937): ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Should I be using a different sort of Connection type or am I missing something from my connection string/s?
The ODBC Administrator (odbcad32.exe) program comes in two versions on 64bit systems. The default one (the one present in the Administrative Tools) is the 64bit version and creates DSN names usable by 64bit programs (or AnyCPU programs that runs on 64 bit OS).
If you want your DSN usable by a 32 bit program create it with the ODBC Administrator available in the c:\windows\SysWOW64 folder.
Of course your application should use the appropriate Target CPU through BUILD -> Configuration Manager, Active Solution Platform.
Sadly I have no answer for the second issue but I hope that the first one is enough to allow you continue on your program

Error: Informix ODBC Driver Network driver cannot open the network device

I have a serious issue with my ODBC Connection to an Informix DB. Trying to connect to the DB leads straight to the following Error and OdbcException.
[HY000] [Informix][Informix ODBC Driver][Informix]Network driver cannot open the network device. (-25574)
This error only appears trying to connect with a c# program. The Connectionstring is
Driver={IBM INFORMIX ODBC DRIVER};Host=xxx;Server=xxx;Service=xxx;Protocol=xxx;Database=xxx;UID=xxx;PWD=xxx
The string has to be ok because its working on my colleagues pc. I've installed the x86 and the x64 bit driver for informix.
The logfile of the odbc connections brings the following error:
dta_302.vshost 10a0-18dc ENTER SQLDriverConnectW
HDBC 0x08428B20
HWND 0x00000000
WCHAR * 0x6F048B34 [ -3] "******\ 0"
SWORD -3
WCHAR * 0x6F048B34
SWORD -3
SWORD * 0x00000000
UWORD 0 <SQL_DRIVER_NOPROMPT>
dta_302.vshost 10a0-18dc EXIT SQLDriverConnectW with return code -1 (SQL_ERROR)
HDBC 0x08428B20
HWND 0x00000000
WCHAR * 0x6F048B34 [ -3] "******\ 0"
SWORD -3
WCHAR * 0x6F048B34
SWORD -3
SWORD * 0x00000000
UWORD 0 <SQL_DRIVER_NOPROMPT>
DIAG [HY000] [Informix][Informix ODBC Driver][Informix]Network driver cannot open the network device. (-25574)
DIAG [HY000] [Informix][Informix ODBC Driver][Informix]Network driver cannot open the network device. (-25574)
This is the first error in the logfile and this error comes up as ODBC exception. There are some more errors in the log. It looks like they are because of the first error.
Until now i have uninstalled and installed the drivers several times with no effect. I've reinstalled Visual Studio. I've also changed some permissions of some registry keys told here ERROR : [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
The very strange thing is if i add the Informix DB to Visual Studio there is obviously no issue and i can use the connection. A test to the logfile shows that there is the same error as well. It seems it was ignored. Same effect if i use the Adoexplorer to connect. It connects and i can work but the error still comes up to the log. My OS is Windows 7 x64. As i said the same configuration is working fine on my colleagues pc.
I've no idea what else to do now. I would be very thankful if anyone could help me.
Edit:
I've to correct me. It seems the Error only appears using the Connection String in the C# Code. There is no Error in the Logfile using the AdoExplorer or connect Database from Visual Studio.
I've finally solved this problem!
In my case my programs are saved on a network directory which is connected to my pc. I've copied the exe file on my C: an it works.
So the problem must have been that i can't run a program via a network directory. Knowing this the error message "cannot open the network device" makes sense. I think normally it had to work as well but for now i am happy with it :)
Thanks for your help.
Edit: using the x86 driver

Error on adding *.accdb to connection string

We are trying to use 64 bit office (2013) from a 32 bit app.
Using the following connection string we are able to access .mdb files.
connection string: Driver={Microsoft Access Driver (*.mdb)};Dbq={Path_To_Db};Uid=;Pwd=;
But when we add *.accdb to the connection string we get the following error for both .mdb as well as .accdb database.
New Connection string: {Microsoft Access Driver (*.mdb, *.accdb)};Dbq={Path_To_Db};Uid=;Pwd=;
Error: [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
On a 32 bit office - the code is working fine.
Any suggestion?

Connection string doesnt work for PostgreSQL

I am using the following connection string structure in my web.config in order to connect to a PostgreSQL database using ODBC however I get an error:
Connection string
<add name="ApplicationODBCDefault" connectionString="Driver={PostgreSQL};Server=127.0.0.1;Port=5432;Database=dbname;Uid=name;Pwd=password;"/>
Error:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I have downloaded and installed both the 32 bit and 64 bit drivers for PostgreSQL ODBC from Here and it still isn't working. What could be the issue here?
Instead of {PostgreSQL} use {PostgreSQL ANSI} or {PostgreSQL UNICODE}
Driver={PostgreSQL UNICODE};Server=127.0.0.1;Port=5432;Database=dbname;Uid=name;Pwd=password;
for more connection strings have a look at: http://www.connectionstrings.com/postgre-sql
You can also configure DSN using ODBC Data Source Administrator and then use created DSN name in ConnectionString:
DSN=dsn_name;Uid=name;Pwd=password;
Look at: https://www.connectionstrings.com/odbc-dsn/
If you are using the 64 bits version of PostgreSQL, then you should use in the connection string:
Driver={PostgreSQL UNICODE(x64)};Server=127.0.0.1; .......

Categories

Resources