For the past week I've been trying to write an application to display product quality based on customer and fiscal period.
The program runs about 15 queries on 3 different servers but despite my best attempts, the final query will not work.
Below you'll find the code as it stands now.
Things I've tried/noticed:
-When i run the stored procedure, the code crashes right at the rs2.open ("splocal_"), strConnect3 line
-This code does work when i substitute the store procedure for select * from table;
-I had the progrm dump the query it tries to run into a text file. That query did work when pasted into the Query Analyzer
-This exact code does work in another application that prints out our certificates of analysis.
-Debugging rs2 and conn2 is showing me that a connection is not being made
Public strConnect3 As String
Public Const PuId As String = "5"
Function test()
call prConnect
Dim conn2 As ADODB.Connection
Set conn2 = New ADODB.Connection
Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset
conn2.Open strConnect3
''''''''''''''''''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
'
' crashes at line below '
' Error 3704: Operation is not allowed when the object is closed. '
''''''''''''''''''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
'''
rs2.Open "splocal_STI_EventData_Res
ult null,null,'" & eventID & "',null,null,'/Report/',nu
ll,null,nu
ll," & PuId, strConnect3
rs2.MoveFirst
While Not rs2.EOF
msgbox rs2.fields(0)
rs2.MoveNext
Wend
rs2.Close
Set rs2 = Nothing
conn2.Close
Set conn2 = Nothing
End Function
Function prConnect()
strConnect3 = "Provider=SQLOLEDB.1;Passw
ord=xxxxx;
Persist Security Info=True;User ID=xxxxx;Initial Catalog=xxxxx;Data Source=xxxxx"
If TestPrConnect() = False Then
MsgBox "connection could not be made.", vbExclamation, "Error"
End If
End Function
Function TestPrConnect() As Boolean
On Error GoTo testError
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.Open strConnect3
'No error means that the connect string works!
If Err.Number = 0 Then TestPrConnect = True
' Clean up and release resources
cnn.Close
Set cnn = Nothing
Exit Function
testError:
MsgBox "connection test error:" & vbCrLf & Err.Number & ": " & Err.Description, vbExclamation, "Error"
End Function