0
votes

Hi Im trying to access MS ACCESS DB via VB and I get this error ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I have done:

  • Change IIS manager -application pool App32 bits to true
  • Downloaded DB drivers for Access
  • Install Access Client

Nothings working at the moment, I've tried from 2 diffrent computers

This is my code

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

Plese help me!

2

2 Answers

0
votes

Your connection string is for OleDb connections and it is not valid for Odbc. you must use something like this for OdbcConnection:

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

you also need to save your access database as '.mdb' file (eg Ms Access 2000 - 2003 format)

Note: There is also another option: if you don't have a reason to use Odbc, why you don't use OleDb which is usually used for microsoft access database? if you want to use OleDb you should use your original(current) connection string but use OleDbConnection for your connection variable and OleDbCommand for your command variable and so on.

0
votes

Also, make sure you have updated VB6 for service pack SP6. It's required to handle MS Access 2000 and later.