none
connecting c# interface to the sql server database RRS feed

  • Question

  • I need the c# code that helps me connects the c# interface to the sql server database...please help me out and if the question isnt clear tell me and ill explain it ...thanx Smile
     
     
    Lubna
    Monday, October 29, 2007 2:19 PM

All replies

  • Please do some research and ask specific questions if needed.

    http://www.google.com/search?hl=en&q=%22ado.net%22+tutorial

     

    Monday, October 29, 2007 3:49 PM
  • Here you go.

     

    Hope this helps:

     

       //Declare the string variable that will contain the connection
       string connectionString;

       connectionString = Data Source=SAMPServer;Initial Catalog=SampDatabase;User ID=UserName;Password=Password;

     

     

       // Declare the SqlConnection that will be used to execute the sql commands
       SqlConnection connection = new SqlConnection(connectionString);

       try
       {
        // Open the connection
        connection.Open();
        connection.Dispose();

        return true;
       }
       //catch (Exception error)
       catch
       {
        // No matter what the error is the database is not available so the system will be offline anyway.
        // If I want to work with the error message I will switch to catch (Exception error) and investigate error.Message
        return false;
       }

     

    Monday, October 29, 2007 4:38 PM
  • Thank you all for your help Smile
    Thursday, December 13, 2007 4:53 PM