Check if there's a open connection to database asp.net/c#
asp.net, c#, database, linq
Solution
You look at the `State` property of any `DBConnection` object, and it will tell you if it's open, closed, connecting, executing, fetching or broken.
By utilizing the `using{ }` statement though, you're guaranteed that the connection is being closed when the object goes out of scope.
Problem
Everytime my application runs a stored procedure it does something like this: ``` using (DbBase conn = new DbBase()) { //call sproc } ``` the `DBBase()` opens the connection with a LINQ `DataContext`. What I wanted to know, if there's a way to know if a connection has already been opened, and use that instead of opening a new one. That verification should be done inside the `DbBase()` constructor that goes like this: ``` ClientDB = new ClientDBDataContext([ConnectionString from web.config]); ``` Thank you