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
    Monday, October 29, 2007 2:19 PM

All replies

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


    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);

        // Open the connection

        return true;
       //catch (Exception error)
        // 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