连接到 MySQL 导致错误“未找到数据源名称且未指定默认驱动程序”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8240050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:48:03  来源:igfitidea点击:

Connecting to MySQL causes error "Data source name not found and no default driver specified"

asp.netmysql

提问by Curt

I'm trying to connect to a MySQL database using my ASP.NET Web Forms Application. I'm carrying out a test to Bind the data from the MySQL database to a GridView.

我正在尝试使用我的 ASP.NET Web 窗体应用程序连接到 MySQL 数据库。我正在执行一项测试,将 MySQL 数据库中的数据绑定到GridView.

Here is my code:

这是我的代码:

Dim strMySQLConn As String = "DRIVER={MySQL ODBC 5.1 Driver};Database=database_name;Server=ip_address;UID=username;PWD=password;"
    Dim MySQLConn As New OdbcConnection(strMySQLConn)

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then

            Dim ds As DataSet = New DataSet()
            Dim cmdMySQL As New OdbcDataAdapter("SELECT * FROM categorymaster", MySQLConn)

            MySQLConn.Open()

            cmdMySQL.Fill(ds, "prjs")

            gv.DataSource = ds.Tables("prjs").DefaultView
            gv.DataBind()


            MySQLConn.Close()

        End If
    End Sub

However, when the MySQL database connection is made (MySQLConn.Open()), the following error is returned:

但是,在建立 MySQL 数据库连接时 ( MySQLConn.Open()),返回以下错误:

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

错误 [IM002] [Microsoft][ODBC 驱动程序管理器] 未找到数据源名称且未指定默认驱动程序

Why is this and how can I prevent it from happening?

为什么会这样,我该如何防止它发生?

Also, what are the possible reasons for seeing this error? If login credentials were incorrect, would this error be shown?

另外,看到此错误的可能原因是什么?如果登录凭据不正确,是否会显示此错误?

回答by Curt

The issue was caused because I was installing a 64-bitMySQL ODBC 5.1 Driver, because my OS is running 64 bit.

问题是因为我正在安装64-bitMySQL ODBC 5.1 驱动程序,因为我的操作系统运行的是 64 位。

Because I've been trying to solve this for days, as a long shot I deleted the driver, and installed 32-bitMySQL ODBC 5.1 Driver.

因为我已经尝试解决这个问题好几天了,所以我删除了驱动程序,并安装了32-bitMySQL ODBC 5.1 驱动程序。

This has fixed the error and I'm now making a successful connection.

这已经修复了错误,我现在正在成功建立连接。

回答by Russell S

Curt was right. I was having this exact issue. Since I had MySQL Workbench installed on my workstation, I assumed I had the drivers installed; Nope. Installing the driver plus calling it by the correct version, and adding command "Provider=MSDASQL;" to the connection string due to the fact that I'm on a 64-bit system solved the issue for me. If you want to see all the ODBC drivers installed on your Windows system, open the registry editor to:

柯特是对的。我遇到了这个确切的问题。因为我的工作站上安装了 MySQL Workbench,所以我假设我已经安装了驱动程序;不。安装驱动程序并通过正确的版本调用它,并添加命令“Provider=MSDASQL;” 由于我使用的是 64 位系统,因此连接字符串为我解决了这个问题。如果要查看 Windows 系统上安装的所有 ODBC 驱动程序,请打开注册表编辑器以:

\HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers.

\HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC 驱动程序。

There you will find out if the MySQL driver is installed, and if so, its correct name.

在那里你会发现是否安装了 MySQL 驱动程序,如果是,它的正确名称。

This Linkwill take you to the MySQL Drivers Download site.

此链接将带您到 MySQL 驱动程序下载站点。

回答by musefan

You might want to check to see if the driver is installed. Here is a guide to getting the list

您可能需要检查是否安装了驱动程序。这是获取列表的指南

Check to see if you have any installed and also make sure your version matches with the one in your connection string.

检查您是否安装了任何版本,并确保您的版本与连接字符串中的版本匹配。

You should be able to download a driver Here

您应该可以在此处下载驱动程序

回答by Tupolev

My solution of "Data source name not found" (with 5.2.4 ODBC ansi driver, Win7 64bit):

我的“未找到数据源名称”的解决方案(使用 5.2.4 ODBC ansi 驱动程序,Win7 64 位):

1) Install 64bit ODBC MySQL driver - it should be visible in ODBC Drivers.

1) 安装 64 位 ODBC MySQL 驱动程序 - 它应该在 ODBC 驱动程序中可见。

2) Install 32bit ODBC MySQL driver - it is invisible in ODBC drivers, but create a "shadow" installation in Program Files x86.

2) 安装 32 位 ODBC MySQL 驱动程序 - 它在 ODBC 驱动程序中不可见,但在 Program Files x86 中创建一个“影子”安装。

That's all.

就这样。

回答by Pablo Iocco

My problem was that I had on my code

我的问题是我的代码

DRIVER={MySQL ODBC 5.3 Driver}, but when I did look up the ODBC trough the windows searcher engine I found an app called ODBC Data Sources, in that app under the Driverstab I found the name of the drives was {MySQL ODBC 5.3 ANSI Driver}. That fixed the problem.

DRIVER={MySQL ODBC 5.3 Driver},但是当我通过 Windows 搜索引擎查找 ODBC 时,我发现了一个名为ODBC Data Sources的应用程序,在该应用程序的Drivers选项卡下,我发现驱动器的名称是 {MySQL ODBC 5.3 ANSI 驱动程序}。这解决了问题。