4
votes

I'm trying to get an ADO connection working in Delphi XE3 and am having major difficulty.

I have an ODBC driver installed on my machine (Win7 x64) the driver shows as 'mySQL ODBC 5.1 driver' under ODBC data sources. Mysql version 5.5.

My understanding is that I should be able to put a TadoConnection component on the form and then assign an appropriate connection string to it as below:

var
  conn: TADOConnection;

procedure TForm1.Button1Click(Sender: TObject);
begin
  conn := conn.Create(nil);
  conn.ConnectionString := 'DRIVER={MySQL ODBC 5.1 Driver}; SERVER=myserver; PORT=3306; DATABASE=mysql; UID=myuser; PASSWORD=mypassword;OPTION=3;';
  conn.Connected := true;
end;

When I run the application and click the button, I get an error

Project Project1.exe raised exception class EOleException with message '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified'.

Can anyone help me? What have I missed? I've tried looking for examples on the web and have had no joy so far.. Any advice is greatly received...

1
Most likely you have configured with C:\Windows\System32\odbcad32.exe instedad of C:\Windows\SysWOW64\odbcad32.exebummi
This is usually a problem of installing the 64-bit driver and then trying to access it from 32-bit code (or vice versa). Are both the driver and your executable the same "bitness" (eg., both 32-bit or both 64-bit)? If so, did you configure the 32-bit ODBC driver (as mentioned by @bummi above)? (The default in Control Panel is the 64-bit ODBC administrator.)Ken White
I think that you could both be onto something. I have opened syswow64\odbcad32.exe and there is no driver available in there. Does that mean that I have got the wrong driver? Which one should I have? I have a 32 bit code base, so should I use a 32 bit driver - I presume that the driver I have is 32 bit as if I open system32\odbcad32.exe the driver shows if I click add (and not in the syswow64\odbcad32.exe)... Thank youMrH
For reference - turns out that the comments left were spot on. I had to remove the existing driver and install the 32 bit version of mysql odbc connector (x86, 32-bit). Used latest version so the connection string driver reads 'DRIVER={MySQL ODBC 5.2a Driver}'.MrH
why u use ADO ? that looks a bit tricky chain: Delphi -> ADO -> ODBC ->mySQL. Perhaps u can get native OLEDB driver to MySQL ? Or perhaps u can use native for Delphi tools like DB Express, ZeosDB, AnyDAC, UniDAC ? Especially given that Microsoft is deprecating ADO starting new project with ADO seems objectable direction. Or at least maybe u can surf through Torry and get some direct ODBC connection component for Delphi.Arioch 'The

1 Answers

1
votes

You just have to check your ODBC Drivers... Go to control panel.. Administrative Tools... and check which ODBC Driver version u have... Then use the right one... For example, I am using the last version of MySQL ODBC. Driver={MySQL ODBC 5.2 ANSI Driver}