SQL Server 2005 데이터베이스에 대해 VB6에서 ADO 명령을 사용하여 설명 할 수없는 오류가 발생합니다. 여기 VB6 ADO SQL Server 명령
문제 입증하는 몇 가지 코드입니다 :Sub ADOCommand()
Dim Conn As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim Cmd As ADODB.Command
Dim ErrorAlertID As Long
Dim ErrorTime As Date
Set Conn = New ADODB.Connection
Conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=database;Data Source=server"
Conn.CursorLocation = adUseClient
Conn.Open
Set Rs = New ADODB.Recordset
Rs.CursorType = adOpenStatic
Rs.LockType = adLockReadOnly
Set Cmd = New ADODB.Command
With Cmd
.Prepared = False
.CommandText = "ErrorAlertCollect"
.CommandType = adCmdStoredProc
.NamedParameters = True
.Parameters.Append .CreateParameter("@ErrorAlertID", adInteger, adParamOutput)
.Parameters.Append .CreateParameter("@CreateTime", adDate, adParamOutput)
Set .ActiveConnection = Conn
Rs.Open Cmd
ErrorAlertID = .Parameters("@ErrorAlertID").Value
ErrorTime = .Parameters("@CreateTime").Value
End With
Debug.Print Rs.State ''// Shows 0 - Closed
Debug.Print Rs.RecordCount ''// Of course this fails since the recordset is closed
End Sub
그래서이 코드는 너무 오래 전에 작업을했습니다하지만 지금은 오류가있는 마지막 줄에 실패하는 것 : 왜
Run-time error '3704': Operation is not allowed when the object is closed
입니다 닫은? 방금 열어 SP가 행을 반환합니다.
내가 추적을 실행하고이는 ADO 라이브러리가 실제로 서버에 제출되는 것입니다 : 물론
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '2010'.
: 내 쿼리 편집기 수익률과는 별개의 일괄 처리로이 실행
declare @p1 int
set @p1=1
declare @p2 datetime
set @p2=''2010-04-22 15:31:07:770''
exec ErrorAlertCollect @[email protected] output,@[email protected] output
select @p1, @p2
오류가 있습니다. 거기에 이중 작은 따옴표를보십시오. 도대체 그게 무슨 소리 야? date 매개 변수에 대한 데이터 형식으로 adDBDate 및 adDBTime을 사용하여 시도해 본 결과 동일한 결과를 제공합니다.
내가 매개 변수 adParamInputOutput을
, 나는이 얻을 : 실행declare @p1 int
set @p1=default
declare @p2 datetime
set @p2=default
exec ErrorAlertCollect @[email protected] output,@[email protected] output
select @p1, @p2
을하는 별도의 배치 수율로 :
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'default'.
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'default'.
도대체? SQL Server는 이러한 종류의 구문을 지원하지 않습니다. 실제 SP 실행 문에서는 DEFAULT 키워드 만 사용할 수 있습니다.
위의 명령문에서 여분의 작은 따옴표를 제거하면 SP가 올바르게 실행됩니다.
... 오 마이. 방금 알아 냈어. 어쨌든 그것은 가치가 있다고 생각합니다.
' ''datetime'''은 프로파일 러의 알려진 버그입니다 (SP2에서 수정 된 것 같습니다) –
감사합니다. 이상한 것은 프로파일 러가 실제 것과 다른 것을보고한다는 것입니다. 서버의 서비스 팩 수준을 확인합니다. – ErikE