Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check is connection to database opened?

I have problem: i don't know how to check does connection to database is established.

I used:

Dim sqlConnection As SqlConnection = New SqlConnection(SQLconnectionEntry)
'SQLconnectionEntry is specified earlier
sqlConnection.Open() 

after opening connection, i have to check is it established, but i stuck.

Any suggestions?

Thx.

EDIT:

Also, how to check does connection is NULL? Thx

EDIT:

I found an answer... simply:

Dim isOpen As Boolean If (sqlConnection.State = ConnectionState.Open) Then isOpen = True Else isOpen = False

And it works for me.

Hope that will help for others.

like image 980
Rusmir Avatar asked Dec 28 '25 16:12

Rusmir


1 Answers

What about:

if (sqlConnection.State = ConnectionState.Open)Then

//Your Code here

End if
like image 120
Ashish Thakur Avatar answered Dec 31 '25 06:12

Ashish Thakur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!