Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class clsSQL
- {
- public string strConn()
- {
- string connString = @"Data Source=xxx.xxx.x.xx\SQLEXPRESS,1433;" +
- "Network Library=DBMSSOCN;" +
- "Initial Catalog=DB;" +
- "User ID=sa;" +
- "Password=xxxxxxxx;";
- return connString;
- }
- public bool isConnected(string connectionString)
- {
- bool bState = true;
- try
- {
- using (SqlConnection conn = new SqlConnection(connectionString))
- {
- conn.Open();
- if (conn.State == ConnectionState.Closed)
- bState = false;
- }
- }
- catch(SqlException ex)
- {
- Console.WriteLine(ex.Message);
- bState = false;
- }
- return bState;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- clsSQL sql = new clsSQL();
- Console.WriteLine(sql.isConnected(sql.strConn()) ? "CONNECTED" : "NOT CONNECTED");
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement