Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How can we check if database and recordset is open or not
Posted
Comments
CHill60 7-May-15 11:04am    
What have you tried?
ZurdoDev 7-May-15 11:49am    
Database and recordset are 2 very different things. What exactly is your question?
Michael_Davies 7-May-15 12:06pm    
You do not show code so difficult to help - what method are you using to connect to DB, ADODB? ODBC? OLEDB?, presume it is ADODB then test the <database object="">.State (1 means it is open).

See https://msdn.microsoft.com/en-us/library/windows/desktop/ms675068%28v=vs.85%29.aspx

Example:
If db.State = ConnectionState.Open Then
<do whatever="">
End If

same goes for recordsets.
Maciej Los 7-May-15 12:33pm    
If it would be an answer, i'll vote for 5!
Michael_Davies 7-May-15 13:59pm    
Difficult to know if it is the answer with such a sparse question and no code shown to be able to tailor the response...

1 solution

You do not show code so difficult to help - what method are you using to connect to DB, ADODB? ODBC? OLEDB?.

I'll presume it is ADODB - test the database-object.State.

See https://msdn.microsoft.com/en-us/library/windows/desktop/ms675068%28v=vs.85%29.aspx[^]

Example:

VB
If db.State = ConnectionState.Open Then
   ' database is open...code here
 End If


same goes for recordsets.
 
Share this answer
 
v3
Comments
Maciej Los 7-May-15 14:10pm    
+5!

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