在我的ASP代碼中,我使用asp引擎將其作爲服務器端腳本運行時沒有任何問題。但是,當我用VB腳本在VBS文件中運行這個相同的連接時,它永遠不會連接到數據庫?我有Windows 2008和2008 R2 MSSQL。有任何想法嗎?VBScript WScript Db連接
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
謝謝,我不知道爲什麼這行之有效於2003年,而不是2008年? Windows明顯改變了這些連接類型的設置。 – 2012-07-25 22:54:12
只是fyi,你的腳本不能在VBS中工作,這是我需要它的地方。我猜測還有比簡單的代碼更改更多。 – 2012-07-25 23:51:48
哪部分不工作? – 2012-07-26 02:24:26