Click here to Skip to main content
16,015,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project user can have a kind of databases ,such as MS SQL Server,MY SQL,...
In a form ,user can select the type of DataBase and its properties(databaseName,username,...)
when the user click on check button,i want to check DataBase Connections if it is true or not!
Posted

The only way to do it is to do a trial connection: set up a SqlConnection object, or a MySqlConnection (or whatever is appropriate) and Open it in a try...catch block. If it succeeds, the database is correct and reachable. If it doesn't, it isn't.

Any other way, such as checking to see if the server instance exists will not verify user login details.
 
Share this answer
 
Hi ,
You can use this
C#
SqlConnection con = new SqlConnection("your connection");
       if (con.State == System.Data.ConnectionState.Closed)
       {
           //con.open();
       }

Best Regards
M.Mitwalli
 
Share this answer
 

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