none
SQL 2000 connection RRS feed

  • Question

  • Iam using Visual Studio 2008 and language is C# to connect to sql server 2000.When Application Executing when it running there is exception error .Below I mention the exception message.But sometime there is no error meassage.I serach in internet but I could not find the result.most of them are for sql server 2005

     A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

    Below I mentio the how I connect to Sql server 2000

      public  class dbEngin
    
    
    
        {
    
    
    
          SqlConnection conn;
    
    
    
            public  static SqlConnection getConnection(){
    
    
    
                
    
    
    
                   SqlConnection con = new SqlConnection("Data Source=CETest;Initial Catalog=SMS_Test;User ID=test;Password=testsms") ;
    
    
    
                
    
    
    
               return con;
    
    
    
            }
    
    
    
    
    
    
    
            public static SqlDataReader getdatareader(string str){
    
    
    
    
    
    
    
               SqlConnection conn = dbEngin.getConnection();
    
    
    
                //logclass.WriteTOLOG(DateTime.Now.ToString() + '\t' + "Establish the  Sql Database connectivity");
    
    
    
               SqlConnection.ClearPool(conn);
    
    
    
               //conn.Close();
    
    
    
               //logclass.WriteTOLOG(DateTime.Now .ToString()+ '\t' + "Close the SQL connectivity");
    
    
    
               conn.Open();
    
    
    
              // logclass.WriteTOLOG(DateTime.Now.ToString()+ '\t' + "Open the SQL connectivity");
    
    
    
               SqlCommand command = new SqlCommand(str, conn);
    
    
    
                // logclass.WriteTOLOG(DateTime.Now.ToString() + '\t'+ "Executing the SQL query"+str);
    
    
    
               return command.ExecuteReader();
    
    
    
               
    
    
    
            }
    Friday, October 2, 2009 12:29 PM

Answers

  • Is your connection string valid? One way to easily test a connection string is to save it as a .udl file. Double-click on the file to load the Data Link Properties dialog, select the Connection tab (if not already selected), and click the Test Connection button. If the test fails use the same dialog to modify your connection, test again and when you're happy click OK to have your modifications saved. Reopen the .udl file in Notepad and extract the correct connection string...

    See this MSDN page for more.
    • Marked as answer by Yichun_Feng Thursday, October 8, 2009 1:38 AM
    Friday, October 2, 2009 1:27 PM