在我的 ASP 代码中,当使用 asp 引擎将其作为服务器端脚本运行时,我没有任何问题。但是,当我在 VBS 文件中使用 VB 脚本运行相同的连接时,它永远不会连接到数据库?我有 Windows 2008 和 2008 R2 MSSQL。有任何想法吗?
establish connection
function DatabaseConnection()
' establish connection if not connected already
if not IsObject(objGlobalConn) then
if Len(Application("WebConnectionString")) = 0 then
Set oShell = CreateObject("WScript.Shell")
Application.Lock
Application("WebConnectionString") = oShell.RegRead("HKLM\SOFTWARE\TB\ConnectionString3")
Application.Unlock
end if
set objGlobalConn = CreateObject("ADODB.Connection")
objGlobalConn.ConnectionTimeout = 0
objGlobalConn.CommandTimeOut = 0
objGlobalConn.CursorLocation = 3 ' adUseClient
objGlobalConn.Open Application("WebConnectionString")
end if
' return connection object
set DatabaseConnection = objGlobalConn
end function
我的 VBScript 文件:
' get the connection string
Set oShell = CreateObject("WScript.Shell")
sConnectionString = oShell.RegRead("HKLM\SOFTWARE\TB\ConnectionString3")
Set oShell = Nothing