Why can't I connect to my access database

2019-04-12 23:18发布

问题:

I'm creating a Microsoft Access 2010 database that will be part of a small web site for a client. I've debugged it with message boxes and I'm able to accept the data with the VBScript (client's choice as they are willing to update/maintain the web site contents), I'm able to call the sub that sends the data to the database, but I can't get past the connection to the database. Here's what I have:

Sub InsertIntoDatabase(FullName)

    Dim strSQL, strConnect, strSQL2, i

    Dim conn

    Set conn = CreateObject("ADODB.Connection")

    strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\userID\Desktop\My Stuff\MyData.accdb"

    ' Cannot get past this point. It's like I cannot connect to the path above.
    conn.Open strConnect

    strSQL = "INSERT INTO SurveyData (FullName, Address, City, State, Zip, Phone, Email, Pentium, PentiumMMX, Macintosh, Series486, Series386, Win2000, WinNT, WinXP, WinVista, Win7, Unix, Shopping"

    strSQL2 = ") VALUES ('" & FullName & "', '" & Address & "', '" & City & "', '" & State & "', '" & Zip & "', '" & Phone & "', '" & Email & "', '" & Pent & "', '" & PentMMX & "', '" & Mac & "', '" & PC486 & "', '" & PC386 & "', '" & Win2000 & "', '" & WinNT & "', '" & WinXP & "', '" & WinVista & "', '" & Win7 & "', '" & Unix & "', '" & Shopping & "'"

    ' End the query string
    strSQL = strSQL & strSQL2 & ")"

    ' Send the query to the database
    conn.Execute strSQL

    ' Close the connection to the database
    conn.Close
    strSQL = ""

end sub

I have another web site that uses a similar script and that one works. Can anyone see something I'm missing?

回答1:

The Jet.OLEDB.4.0 provider works for MDB format database files. For the newer ACCDB format (MyData.accdb), you need the ACE provider.

For Access 2007, there was only a 32 bit version of the ACE provider. But starting with Access 2010, there are separate 32 and 64 bit versions. You need the one which matches the bit mode in which your VBScript runs.



回答2:

Try changing your connection string to use the ODBC. Per Connection Strings

Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;
Uid=Admin;Pwd=;