未找到源名称且未指定默认驱动程序111

时间:2013-09-24 03:54:25

标签: vb.net ms-access

您好我试图通过VB访问MS ACCESS数据库,我收到此错误 错误[IM002] [Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序

我做了:

  • 将IIS管理器 - 应用程序池App32位更改为true
  • 已下载用于访问的数据库驱动程序
  • 安装Access Client

目前没有工作,我尝试过两台不同的电脑

这是我的代码

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button1.Click

    Dim vConnectionStringX As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\1767631\db_Assign_2.accdb;Persist Security Info=False;"
    Dim rtfConn As New Data.Odbc.OdbcConnection(vConnectionStringX)
    rtfConn.Open()






    Dim cusFName As String = TextBox1.Text
    Dim cusLName As String = TextBox2.Text
    Dim cusTP As String = TextBox3.Text
    Dim cusEmail As String = TextBox4.Text

    Dim vSQL As String = "Insert into Customer(FirstName, LastName, Telephone, Email) Values (" & cusFName & "," & cusLName & "," & cusTP & "," & "cusEmail"")"

    Try
        Dim rtfSQLCMD As New Data.Odbc.OdbcCommand
        rtfSQLCMD.Connection = rtfConn
        rtfSQLCMD.CommandText = vSQL
        Dim vResult As Integer = rtfSQLCMD.ExecuteNonQuery
        MessageBox.Show("Customer registered! " & vResult)

    Catch ex As Data.Odbc.OdbcException
        Dim vErMsg As String = "*** Error occured while registering the customer ***" & ControlChars.NewLine

    End Try

    rtfConn.Close()

End Sub

请帮助我!

2 个答案:

答案 0 :(得分:0)

您的连接字符串用于OleDb连接,它对Odbc无效。你必须为OdbcConnection使用类似的东西:

Dim vConnectionStringX As String = "Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\db1.mdb"

您还需要将访问数据库保存为“.mdb”文件(例如Ms Ms 2000 - 2003格式)

注意:还有另一种选择:如果您没有理由使用Odbc,为什么不使用通常用于微软访问数据库的OleDb?如果你想使用OleDb,你应该使用原始(当前)连接字符串,但是使用OleDbConnection作为连接变量,使用OleDbCommand作为命令变量,依此类推。

答案 1 :(得分:0)

此外,请确保已更新Service Pack SP6的VB6。它需要处理MS Access 2000及更高版本。