Deepali Patil

Deepali Patil

  • 1.9k
  • 142
  • 51.5k

Hi,I have created a Web Service with a method "GetUserDetails". When i run the Web Service i get the foolowing error?

Jan 13 2013 4:13 AM
I have written the following method:

        public XmlElement GetUserDetails(string Name)
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
            SqlCommand cmd = new SqlCommand("select * from Customers where Name like @Name+'%'", con);
            cmd.Parameters.AddWithValue("@Name", Name);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            // Create an instance of DataSet.
            DataSet ds = new DataSet();
            // Return the DataSet as an XmlElement.
            XmlDataDocument xmldata = new XmlDataDocument(ds);
            XmlElement xmlElement = xmldata.DocumentElement;
            return xmlElement;

In the web.config file, I have written the following code:

    <add name="dbconnection" connectionString="Data Source=localhost;Initial Catalog=MySampleDB;Integrated Security=True;" providerName="System.Data.SqlClient" />

I get the following error :
System.Data.SqlClient.SqlException: 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)

Answers (1)