0

hi everyone,
is there any way that I can programatically tell the user weather he/she is successfully connected to the database(SQL Server 2005). or connection failed.
Code is written in C#.

string Connectionstring = "....";
sqlConnection con = new sqlConnection(Conncetionstring);
con.Open();

how I can check programatically weather con.Open() is sucess of failed.

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Renukavani
0

You can use like this,

string Connectionstring = "....";
sqlConnection con = new sqlConnection(Conncetionstring);
try
        {
            con .Open();
        }
        catch (SqlException exp)
        {
//assigned into string vari
            strErrorState = exp.Message;
        }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.