As a programmer, one of the most common tasks in your application is to connect to the database. Here’s a very simple way to check your database connection before you start any task or use this as a service to check the connection and pause tasks if the connection breaks.
private static bool DBConnectionStatus()
using (SqlConnection sqlConn =
return (sqlConn.State == ConnectionState.Open);
VB.NET (Converted Code)
Private Function DBConnectionStatus() As Boolean
Using sqlConn As New SqlConnection("YourConnectionString")
Return (sqlConn.State = ConnectionState.Open)
Catch e1 As SqlException
Catch e2 As Exception
The code above opens a connection to the database and returns a boolean depending on the database status.
Will you give this article a +1 ? Thanks in advance