0
我們有一個VBScript,可將SAP Business Object數據庫中的數據塊下載到所謂的片中,這些片基本上是.csv文件。這個腳本迄今爲止工作得很完美,我根本沒有必要去研究它。但現在失敗是這樣的:腳本失敗,錯誤代碼爲80040E31
腳本文件一節這個錯誤指的是在下面的代碼的dbConn.Execute(strSQL)
線(從下面5日)。 我試了一下,到目前爲止,是添加這些命令,但他們似乎並沒有解決任何問題:
'dbConn.ConnectionTimeout = 100
'dbConn.CommandTimeout = 100
腳本本身(而不是全部的話,我不知道需要休息) :
Sub subRunFilesInFolder(strFolder)
Dim FSO, objFolder, objFiles
Dim i, intTS, intTS_file_start, ts, tsKillBefore, TS_file_start, strModelName
Dim dbConn, RST, RST2, strSQL
Dim strVBSmodel
Dim blRunIt
'INIs
strModelName = "bo_vbs_runner_1.5 "
strConn = "DRIVER={SQL Server};SERVER=EUBASEURCIREP01;UID=ser_login;PWD=ser_login;DATABASE=ser"
strComputer = FunstrComputerName
strBORunner = "\\Eubaseurcirep01\reporting\DEVELOPMENT\BO\Automation\Models\BO_auto_run.xlsb"
'Sets
Set dbConn = CreateObject("ADODB.Connection")
Set RST = CreateObject("ADODB.RecordSet")
Set RST2 = CreateObject("ADODB.RecordSet")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set objFolder = FSO.GetFolder(strFolder)
Set objFiles = objFolder.Files
Set appExcel = CreateObject("Excel.Application")
'dbConn.ConnectionTimeout = 100
'dbConn.CommandTimeout = 100
strVBSmodel = strModelName & strComputer & " " & FunstrUserName & " " & funCurrProcessId & " " & FunGetProcessIDCurrentOfExcel(strComputer)
appExcel.Application.Visible = False
appExcel.Displayalerts = False
Set objBORunner = appExcel.Workbooks.Open(strBORunner)
dbConn.Open strConn
ts = FunGetServerNow(dbConn,RST)
tsKillBefore = DateAdd("N", -15, ts)
intTS = funTimeStampToInteger(FunGetServerNow(dbConn, RST))
'Get ReportDate
strSQL = "SELECT yyyymmdd FROM map.reportdate WHERE dtAct=cast(GETDATE() as DATE);"
RST.Open strSQL, dbConn
If RST.EOF Then
strReportDate="99991231"
Else
strReportDate=RST.fields(0).value
End If
RST.close
'Kill stucked excel and vbs processes
strSQL = "SELECT distinct * FROM [ser].[bo].[_log] WHERE [proc]='BO VBS' AND result_text='started' AND end_timestamp<" & funTimeStampToInteger(tsKillBefore) & _
" AND lower(model) like '% " & LCase(strComputer) & " %';"
RST.Open strSQL,dbConn
If RST.EOF Then 'Nothing to kill
Else
Do While Not RST.EOF
strOldVBS = split(RST.fields("model"), " ")(3)
strOldExcel = split(RST.fields("model"), " ")(4)
Call SubKillProcessIDOnstrComputer(strComputer, strOldVBS)
Call SubKillProcessIDOnstrComputer(strComputer, strOldExcel)
strSQL = "UPDATE [ser].[bo].[_log] SET result_text='stopped', end_timestamp='" & funTimeStampToInteger(FunGetServerNow(dbConn,RST2)) & "' " & _
"WHERE [proc]='BO VBS' AND result_text='started' AND model='" & RST.fields("model").value & "' AND parameters='" & _
RST.fields("parameters").value & "';"
dbConn.Execute(strSQL)
RST.MoveNext
Loop
End If
RST.close
它是否有助於超時設置爲'0'?根據文檔,命令應該運行「只要它需要」:'如果您將屬性設置爲零,ADO將無限期地等待,直到執行完成。 - https://msdn.microsoft.com/en- us/library/ms678265%28v = vs.85%29.aspx – erg
這聽起來很不錯 - 但恐怕有些東西卡住了,因爲我將超時設置爲0,所以錯誤沒有出現,但是沒有其他事情發生。現在腳本已經運行了半個小時 - 第一片應該在幾分鐘內到達。 – user2870283
是的,聽起來像查詢在sql server本身被阻止。我會嘗試在服務器端分析什麼導致阻塞,使用從SQL服務器的工具 - 我不知道如何做到這一點,但這裏看起來像一個開始:http://stackoverflow.com/questions/941763/ list-the-queries-running-on-sql-server 另外我會嘗試確定服務器端是否有任何更改等。 祝你好運,新年快樂! PS:當然,嘗試像重新啓動/重新啓動SQL服務器等明顯的東西.. – erg