none
Error in connecting to SQL SERVER : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) RRS feed

  • Question

  • Hi All

    I am a beginner learning ADO.NET. I am using the Microsoft Visual Studio 2005 and SQL Server 2005.

    I have written the following codings in Visual Studio:

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

    /// <summary>
    ///
    Demonstrates how to work with SqlConnection objects
    /// </summary>
    class SqlConnectionDemo
    {
        static void Main()
        {
            // 1. Instantiate the connection
             SqlConnection conn = new SqlConnection(
                
    "Data Source=(local);Initial Catalog=AdventureWorks;User ID = SNK; Password = 123456789");

             SqlDataReader rdr =
    null ;

             try
           {

                 conn.Open();

                SqlCommand cmd = new SqlCommand("select * from Customers", conn);

                 rdr = cmd.ExecuteReader();

                 // print the CustomerID of each record
                 while (rdr.Read())
                {
                    Console.WriteLine(rdr[0]);
                 }
             }
             finally
             {
                 if (rdr != null )
                 {
                     rdr.Close();
                 }

                 if (conn != null )
                 {
                     conn.Close();
                 }
             }
        }
    }

    When I execute the above query it is showing the following error:

    An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
     

    Please note that  in SQL SERVER CONFIGURATION AREA MANAGER - REMOTE CONNECTION I have selected :
    Using Local and Remote Connections:
     Using TCP/IP and NamedPipes.

    Can any one help me identify what the error is and how to resolve the error?

    Please help me!

    Thanks in advance!!1
    • Moved by Matt Meehan - MSFTModerator Tuesday, May 19, 2009 9:20 PM Not ADO.NET Data Services related (From:ADO.NET Data Services (Pre-Release))
    Tuesday, May 19, 2009 5:50 PM

Answers

All replies