[RESOLVED] Run-Time Error 3265
Hello,
Getting the below error (happens at red text) when running a sql command from vb. From other posts it appears to be due to invalid field names. But when I run the same script from Query Analyzer it returns the expected results. Is there a server setting that might cause this issue? I have no issues retreiving data from other types of databases, just this kind.
Run-time error '3265': Item cannot be found in the collection to the requested name ordinal.
vb Code:
Public Sub ConnectToServer(Database As String)
' On Error GoTo leave
Dim Kent As String
If Conn1.State = adStateOpen Then Set Conn1 = Nothing
Conn1.Open "Driver={SQL Server};Server=LDMRMS01;Trusted_Connection=yes;"
Set Cmd1.ActiveConnection = Conn1
Cmd1.CommandTimeout = 600
If Len(Database) > 0 Then
Cmd1.CommandText = "Use " & Trim(Database)
Cmd1.Execute
End If
rs1.CursorLocation = adUseClient
'!!!!TESTCODE
If Database = Trim(Exposure.ExposureDBs.Text) And Database > "" Then
Cmd1.CommandText = "SELECT PORTNAME, PORTINFOID From portinfo " & _
"GROUP BY PORTNAME, PORTINFOID ORDER BY PORTNAME"
[COLOR="Red"]rs1.Open Cmd1, , adOpenStatic, adLockBatchOptimistic[/COLOR]
While Not rs1.EOF
Kent = rs1(0)
rs1.MoveNext
Wend
rs1.Close
End If
'!!!!TESTCODE
GoTo leave2
leave:
If Conn1.State = adStateOpen Then Set Conn1 = Nothing
If rs1.State = adStateOpen Then rs1.Close
leave2:
End Sub
Thanks for any help that might be provided!
Re: [RESOLVED] Run-Time Error 3265
You should always close and set to nothing your recordset object each and everytime you use it.