Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a VB.Net application which was running perfect for like 20 days as a Windows service 24/7 (10 minute periodical times). All of the sudden it started throwing me an error in the log file "Exception Occurred with closing the recordset1 : Operation is not allowed in this context.". Now when I stop the service and starts back the first time it runs without any issue but the next iteration(after 10th minute) it throws me that error.



The log file report as following :
9/23/2021 10:15:28 AM - Wisys Objects Connected to Database!
9/23/2021 10:15:28 AM - DRIVER={SQL Server};Server=STLEDGSQL01;UID=****PWD=*******;DATABASE=100
9/23/2021 10:15:28 AM - Macola Connection State : 1
9/23/2021 10:15:28 AM - Inside the try, cnADOMacola connection closed!
9/23/2021 10:15:28 AM - Macola Connection opened again!
9/23/2021 10:15:28 AM - Exception Occured with closing the recordset1 : Operation is not allowed in this context.
9/23/2021 10:15:28 AM - Exception Occured with opening the recordset to get the company name via cnADOMacola : Operation is not allowed when the object is open.
9/23/2021 10:15:28 AM - Exception Occured with opening the connection ADOEDGE_DSN : Item cannot be found in the collection corresponding to the requested name or ordinal.

What I have tried:

VB
Sub SFCActivityTransactions()
Do
lngST = lngST + 1

Dim p_sRtnErrMsg = ""
If WiSysConn.TestConnectivity(p_sRtnErrMsg) = False Then
If lngST >= 3 Then
strStatus = "Wisys objects failed to connect to database. " & p_sRtnErrMsg
FileIO.WriteLog(strStatus)
Exit Do
End If
Else
strStatus = ""
Exit Do
End If
Loop

strConnectionString = "DRIVER={SQL Server};Server=" & g_sRtnServer & ";UID=" & g_sSQLUser & ";PWD=" & g_sSQLPass & ";DATABASE=" & g_sRtnDatabase

FileIO.WriteLog(strConnectionString)

FileIO.WriteLog("Macola Connection State : " & cnADOMacola.State)

Try
If cnADOMacola.State = 1 Then cnADOMacola.Close()
FileIO.WriteLog("Inside the try, cnADOMacola connection closed!")
Catch ex As Exception
FileIO.WriteLog("Exception occured in closing existing Macola connection : " & ex.Message)
End Try

cnADOMacola.ConnectionString = strConnectionString
FileIO.WriteLog("Macola Connection State : " & cnADOMacola.State)
Try
cnADOMacola.Open(strConnectionString)
lngST = Err.Number
strMsg = Err.Description
FileIO.WriteLog("Macola Connection opened again!")
FileIO.WriteLog("Macola Connection State : " & cnADOMacola.State)
Catch ex As Exception
FileIO.WriteLog("Exception Occured with opening the Macola connection via cnADOMacola : " & ex.Message)
End Try


If lngST <> 0 Then
strStatus = "There was an error trying to connect to the " & g_sRtnDatabase & " database. Error " & lngST & " - " & strMsg & ". Program ends now!"
FileIO.WriteLog(strStatus)
OnStop()
End If

strSelectStatement = "SELECT bedrnm FROM [100].[dbo].[bedryf] WHERE ID = 1"


Try
If rs1 Is Nothing Then
If rs1.State = 1 Then
rs1.Close()
FileIO.WriteLog("Inside the try block after closing the recordset 1")
End If
End If
Catch ex As Exception
FileIO.WriteLog("Exception Occured with closing the recordset1 : " & ex.Message)
End Try

Try
'If rs1 Is Nothing Then
rs1.Open(strSelectStatement, cnADOMacola, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
FileIO.WriteLog("Inside the try block after re-opening the recordset 1 with strSelectStatement")
'End If
Catch ex As Exception
FileIO.WriteLog("Exception Occured with opening the recordset to get the company name via cnADOMacola : " & ex.Message)
End Try


If rs1.EOF Then
strStatus = "There was an error finding the company name. Program exits now!"
FileIO.WriteLog(strStatus)
OnStop()
Else
Try
FileIO.WriteLog("Company Name : " & rs1.Fields("bedrnm").Value)
Catch ex As Exception
FileIO.WriteLog("Exception Occured with opening the connection ADOEDGE_DSN : " & ex.Message)
End Try

End If
Posted
Updated 23-Sep-21 11:45am
v2
Comments
Richard Deeming 24-Sep-21 8:58am    
You're using VB.NET, so why are you still using the ancient and practically-obsolete ADODB library? .NET includes ADO.NET, which is much more powerful, and much simpler to use.

1 solution

As far as I can see you never close the recordset:
If rs1 Is Nothing Then
If rs1.State = 1 Then
rs1.Close()
FileIO.WriteLog("Inside the try block after closing the recordset 1")
End If
End If
That call will never happen, because if rs1 is Nothing, it can't have a State property ...

I'd start with your log, and see what is going on while it's running - that is after all what keeping a log file is for!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900