I am in need of using Classic ASP with A开发者_JS百科ccess. This is a requirement unfortunately. I currently have a script which connects to the Access DB just fine. Here is the snippet:
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db1.mdb")
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * from table1;"
rsGuestbook.Open strSQL, adoCon
Again, this snippet works just fine, records sent to browser.
When I apply this connection to a different script, I get an error returned which states: Microsoft VBScript compilation error '800a0415' Expected literal constant Const ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)} DBQ=" & Server.MapPath("db1.mdb")
Here is the connection snippet:
Const ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db1.mdb")
Appreciate any guidance anyone can throw my way, I know this is some old school, anyone else remeber when this stuff was bleeding edge? LOL I do...
Don't use a constant for your connection string. Since Server.MapPath
is indeterminate (paths could change from one run to the next), Const
is complaining. Or, it might complain with any concatenation when assigning a constant, I can't remember for sure...
Instead, change:
Const ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db1.mdb")
to:
Dim ConnectionString
ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db1.mdb")
精彩评论