简体   繁体   中英

Accessing MySQL via C# program - ERROR [IM002] Data source name not found and no default driver specified

I'm debugging an old C# program that was designed to take in .dbf files, connect to a database (for some reason*), and then output those .dbf files in a more human-friendly, formatted manner (an Excel file). A released version of this program (years ago) works fine, but has some things that need ironing out. Hence, my attempts to debug the available Visual Studio Solution.

I'm having trouble with the connect to a database part, as the program returns the above error.

I'm not at all too experienced with MySQL, but I'll try to give all the details I can.

The program is being debugged in Visual Studio 2005. It was probably created there too, although some things look outdated. My OS is Windows 7, 32-bit.

I'm using MySQL version 3.23.42, and is installed on the very computer where the program is running. No network setups here, since the Database likely stores temporary data, and then outputs it to the Excel file.

I'm not sure if this is correct (ODBC? Instead of SQL?), but this is at the top of the program:

using System;
using System.Data;
using System.Data.Odbc;
using System.Windows.Forms;

I also had the MyODBC 3.51.05 installed.

Here's the connection string (note: I did not write this, it was already there):

string str_connection="DRIVER={MySQL ODBC 5.1 Driver};SERVER="localhost";DATABASE="TKCinterface";UID="ids";PASSWORD="ids";OPTION=3";

The program fails when it tries to open a connection, which I assume has something to do with the connection string.

My attempts to manually connect via Tools -> Connect To Database was met with failure, or at least the options I chose.

  • Data source: Microsoft ODBC Data Source
  • Data provider: .NET Framework Data Provider for ODBC

I don't see the database in the Window that follows.

I can open up MySQL via the Command line, and also see the database (TKCInterface), so I'm not sure what the problem is.

Curiously, there is nothing that references MySQL in the References of the project. The whole thing builds fine, though.

Any help on this would be much appreciated. Thanks.

Regards, Zack_Falcon

Specify the port with which you are connecting to mysql

change the connection sting to

 string str_connection="DRIVER={MySQL ODBC 5.1 Driver};SERVER="localhost";DATABASE="TKCinterface";UID="ids";PASSWORD="ids";Port=3306;";

Hope this helps

You definately need mysql.data and mysql.data.entity in your reference list.

Download the libaries from here http://dev.mysql.com/downloads/connector/net/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM