Deal with connection exception : SqlConnection : ADO.Net C# Examples


C# Examples » ADO.Net » SqlConnection »

 

Deal with connection exception









    
using  System;
using  System.Data;
using  System.Data.SqlClient;

class  MainClass
{
      static  void  Main(string[]  args)
      {
            string  connString  =  "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated  Security=SSPI;";

            SqlConnection  conn  =  new  SqlConnection(connString);  

            try  {
                  conn.Open();
                  Console.WriteLine("Connection  opened.");
            }
            catch  (SqlException  e)  {
                  Console.WriteLine("Error:  "  +  e);
            }
            finally  {
                  conn.Close();
                  Console.WriteLine("Connection  closed.");
            }
      }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» SqlConnection