简体   繁体   English

经典ASP Access数据库连接问题

[英]Classic ASP Access Database Connection Trouble

I am in need of using Classic ASP with Access. 我需要在Access中使用Classic ASP。 This is a requirement unfortunately. 不幸的是,这是一个要求。 I currently have a script which connects to the Access DB just fine. 我目前有一个可以很好地连接到Access DB的脚本。 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") 当我将此连接应用于其他脚本时,返回以下错误:Microsoft VBScript编译错误'800a0415'预期的文字常量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. 由于Server.MapPath是不确定的(路径可能从一次运行更改为下一次运行),因此Const抱怨。 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")   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM