그래서 이전 Classic ASP 웹 사이트를 업데이트하라는 요청을 받았습니다. 그것은 매개 변수화 된 쿼리를 사용하지 않았으며 입력 검증은 거의 이루어지지 않았습니다. 간단한 작업을 위해 필자는 데이터베이스 연결을 열고 매개 변수가있는 명령 개체를 설정하고 연결이 끊긴 레코드 세트를 만드는 도우미 함수를 작성했습니다. :)] 여기에 코드입니다 :기존 ASP 연결이 끊긴 레코드 집합 문제
Function GetDiscRS(DatabaseName, SqlCommandText, ParameterArray)
'Declare our variables
Dim discConn
Dim discCmd
Dim discRs
'Build connection string
Dim dbConnStr : dbConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & rootDbPath & "\" & DatabaseName & ".mdb;" & _
"Persist Security Info=False"
'Open a connection
Set discConn = Server.CreateObject("ADODB.Connection")
discConn.Open(dbConnStr)
'Create a command
Set discCmd = Server.CreateObject("ADODB.Command")
With discCmd
Set .ActiveConnection = discConn
.CommandType = adCmdText
.CommandText = SqlCommandText
'Attach parameters to the command
If IsArray(ParameterArray) Then
Dim cnt : cnt = 0
For Each sqlParam in ParameterArray
discCmd.Parameters(cnt).Value = sqlParam
cnt = cnt + 1
Next
End If
End With
'Create the Recordset object
Set discRs = Server.CreateObject("ADODB.Recordset")
With discRs
.CursorLocation = adUseClient ' Client cursor for disconnected set
.LockType = adLockBatchOptimistic
.CursorType = adOpenForwardOnly
.Open discCmd
Set .ActiveConnection = Nothing ' Disconnect!
End With
'Return the Recordset
Set GetDiscRS = discRS
'Cleanup
discConn.Close()
Set discConn = Nothing
discRS.Close() ' <=== Issue!!!
Set discRs = Nothing
Set discCmd = Nothing
End Function
내 문제는 내가 함수의 끝에서 discRS.Close()
를 호출하는 경우, 다음 반환되는 레코드가 채워되지 않는 것입니다. 이로 인해 레코드 세트가 실제로 연결이 끊어 졌는지 아닌지 궁금하게되었습니다. 내가 그 라인에 대해 논평하면 모든 것이 제대로 작동한다. 또한 ActiveConnection = Nothing
을 설정하기 전과 후에 discRS 값을 사용하는 함수 내에서 Response.Write()
을 수행하고 레코드 세트 값을 올바르게 반환했습니다. 그래서 그것은 discRS.Close()
으로 격리 된 것 같습니다.
이전 기사가 4guysfromrolla.com 인 것으로 밝혀졌으며 기능에 Close()
레코드 세트를 발행합니다. 다른 사이트에서도 똑같은 것을 보았습니다. 그게 실수 였는지, 아니면 뭔가가 바뀌 었는지 확실하지 않습니다.
참고 :
Set .ActiveConnection = Nothing ' Disconnect!
그래서,이 레코드가 이미 폐쇄되지 않은 : 나는 내가 볼 수있는 코드에서
getRows()를 사용하여 레코드 세트를 메모리 내 변수에 할당 할 수도 있습니다. 참조하십시오 : http://stackoverflow.com/questions/8916384/asp-getrows-count –
Diodeus,하지만 가능하면 인덱스 대신 열 이름을 사용하는 대신 어떤 요소가 어떤 위치에 있는지 기억해야합니다. – Sam