반응형
짧은 프로시저를 실행하려고 할 때 쿼리 시간 초과가 만료됨
제 연결 문자열은 다음과 같습니다.
Global Const strConn As String = _
"PROVIDER=SQLNCLI10;" & _
"P-SSWORD=blahblah;" & _
"USER ID=blahblah;" & _
"INITIAL CATALOG=blah;" & _
"DATA SOURCE=blah;" & _
"CONNECT TIMEOUT=0;" & _
"COMMAND TIMEMOUT=0" & _
"PACKET SIZE=4096;"
간단한 코드는 다음과 같습니다.
Sub MoveDataUsingADO()
Dim cn As Object
Dim cm As Object
Dim rs As Object
'get in touch with the server
'Create ado objects.
Set cn = CreateObject("ADODB.Connection")
cn.connectiontimeout = 0
cn.Open strConn
cn.CommandTimeout = 0
Set cm = CreateObject("ADODB.Command")
Set cm.ActiveConnection = cn
cm.CommandType = 4 'adCmdStoredProc
Set rs = CreateObject("ADODB.Recordset")
Set rs.ActiveConnection = cn
cm.CommandText = "WH.dbo.ourProcName"
With wb.Sheets("Data")
.Activate
.Range(.Cells(2, 1), .Cells(.Cells(.Rows.Count, 2).End(Excel.xlUp).Row + 1, .Cells(1, .Columns.Count).End(Excel.xlToLeft).Column)).ClearContents
End With
With rs
.Open Source:=cm.Execute '<=====errors here===========
wb.Sheets("Data").Cells(wb.Sheets("Data").Rows.Count, 1).End(Excel.xlUp)(2, 1).CopyFromRecordset rs
.Close 'close connection
End With
...
...
위에 표시된 지점에서 다음과 같은 오류가 발생합니다.

이해가 안 가요. 이 시술은 55초가 걸려요vba시간 초과를 설정했습니다.0... 이것 때문에 그들이 만료되지 않을 수 밖에 없었다고 생각했는데요?
명령에 명시적으로 타임아웃을 설정해 보았습니까?
cm.CommandTimeout = 0
연결을 설정하는 것보다.연결 타임아웃은 명령을 실행하는 시간인 반면 명령 타임아웃은 거부하기 전에 연결을 설정할 수 있는 시간과 관련이 있다고 생각합니다.
쿼리를 실행하는 데 얼마나 걸리는지 알고 계십니까?혹시 타임아웃 기간과 다른 문제가 있는 것은 아닐까요?
명령 개체에 대해 다음과 같이 시간 초과를 설정해야 합니다.
cm.CommandText = "WH.dbo.ourProcName"
cm.CommandTimeout = 120
With wb.Sheets("Data")
.Activate
.Range(.Cells(2, 1), .Cells(.Cells(.Rows.Count, 2).End(Excel.xlUp).Row + 1, .Cells(1, .Columns.Count).End(Excel.xlToLeft).Column)).ClearContents
End With
With rs
.Open Source:=cm.Execute '<=====errors here===========
wb.Sheets("Data").Cells(wb.Sheets("Data").Rows.Count, 1).End(Excel.xlUp)(2, 1).CopyFromRecordset rs
.Close 'close connection
End With
언급URL : https://stackoverflow.com/questions/19758773/query-timeout-expired-when-trying-to-run-a-short-procedure
반응형
'programing' 카테고리의 다른 글
| Jquery가 문자열로 시작하는 모든 ID를 찾습니까? (0) | 2023.10.14 |
|---|---|
| 이벤트 스케줄러 상태를 확인하는 방법 mysql (0) | 2023.10.14 |
| ASP.NET MVC 6 AspNet.세션 오류 - 유형에 대한 서비스를 확인할 수 없습니까? (0) | 2023.10.14 |
| 함수와 같은 매크로에 전처리기 지시어를 추가하는 것이 잘못된 것입니까? (0) | 2023.10.14 |
| Excel VBA에서 텍스트 파일에 어떻게 안정적으로 쓸 수 있습니까? (0) | 2023.10.14 |