Why can't I connect to my access database

戏子无情 提交于 2019-12-06 11:21:49

问题


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=;


来源:https://stackoverflow.com/questions/21262429/why-cant-i-connect-to-my-access-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!