使用 VBscript 检查 MS access 数据库是否存在
checking if a MS access database exists using VBscript
我一直在使用不同的搜索词搜索年龄,但找不到问题的答案。
我正在使用 asp 操作 MS Access 数据库,该数据库保存在根文件夹上方的文件夹中。
为了连接到数据库,我使用了以下有效的代码:
set Conn = server.createobject("ADODB.CONNECTION")
conn.ConnectionString="DBQ=" & server.mappath("../../db") & "\renewx.mdb"& ";Driver={Microsoft Access Driver (*.mdb)};"
但是,我想在连接之前检查数据库是否存在,这里我遇到了一些困难。
我的代码是:
set fs=Server.CreateObject("Scripting.FileSystemObject")
if File.Exists(Server.MapPath("../../db") & "\renewx.mdb") then
response.write("renewx dbase exists!<br>")
else
response.write("renewx dbase does not exist!<br>")
set fs=nothing
response.end
end if
set fs=nothing
这会产生错误:
800a01a8|Object_required:_'File' HTTP/1.1 (the line triggering the
error is the first line of the if condition)
如果有人能指出正确的方向,非常感谢。
托格
试试这个:
set fs=Server.CreateObject("Scripting.FileSystemObject")
'if File.Exists(Server.MapPath("../../db") & "\renewx.mdb") then
if fs.FileExists(Server.MapPath("../../db") & "\renewx.mdb") then
确保在 IIS 服务器上启用了父路径。默认情况下它们被禁用。
Link to Microsoft documentation for IIS 8
我一直在使用不同的搜索词搜索年龄,但找不到问题的答案。
我正在使用 asp 操作 MS Access 数据库,该数据库保存在根文件夹上方的文件夹中。
为了连接到数据库,我使用了以下有效的代码:
set Conn = server.createobject("ADODB.CONNECTION")
conn.ConnectionString="DBQ=" & server.mappath("../../db") & "\renewx.mdb"& ";Driver={Microsoft Access Driver (*.mdb)};"
但是,我想在连接之前检查数据库是否存在,这里我遇到了一些困难。
我的代码是:
set fs=Server.CreateObject("Scripting.FileSystemObject")
if File.Exists(Server.MapPath("../../db") & "\renewx.mdb") then
response.write("renewx dbase exists!<br>")
else
response.write("renewx dbase does not exist!<br>")
set fs=nothing
response.end
end if
set fs=nothing
这会产生错误:
800a01a8|Object_required:_'File' HTTP/1.1 (the line triggering the error is the first line of the if condition)
如果有人能指出正确的方向,非常感谢。
托格
试试这个:
set fs=Server.CreateObject("Scripting.FileSystemObject")
'if File.Exists(Server.MapPath("../../db") & "\renewx.mdb") then
if fs.FileExists(Server.MapPath("../../db") & "\renewx.mdb") then
确保在 IIS 服务器上启用了父路径。默认情况下它们被禁用。 Link to Microsoft documentation for IIS 8