连接到MySQL会导致错误“找不到数据源名称且未指定默认驱动程序". [英] Connecting to MySQL causes error "Data source name not found and no default driver specified"

查看:120
本文介绍了连接到MySQL会导致错误“找不到数据源名称且未指定默认驱动程序".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这是我的代码:

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

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

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

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

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

这是为什么,如何防止它发生?

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?

推荐答案

引起此问题的原因是我安装了64-bit MySQL ODBC 5.1驱动程序,因为我的操作系统运行的是64位.

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

因为几天来我一直在尝试解决此问题,所以从长远来看,我删除了该驱动程序,并安装了32-bit MySQL ODBC 5.1驱动程序.

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

这已解决了该错误,我现在已经建立了成功的连接.

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

这篇关于连接到MySQL会导致错误“找不到数据源名称且未指定默认驱动程序".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆