Search code examples
c#.netconnection-stringsqlexception

Database connection not working - System.Data.SqlClient.SqlException: No process is on the other end of the pipe


I am trying to connect to a database on my local machine, but keep getting an error.

This is just for a school project, but I can't seem to figure out where I am going wrong. I reviewed a lot of other answers, and tried what they suggested, but have yet to find success. The goal at this point is for my method to return an open connection so that I may use it throughout my App.

Here is my connection string:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
       <add name="AdventureWorks"
            connectionString="data source=Desktop;initial catalog=AdventureWorksLT2008R2"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

Here is my method that returns an open connection:

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

namespace Repository.DataAccess
{
   public class DBFactory
   {
       public static IDbConnection GetLocalDbConnection()
       {
            string conn = ConfigurationManager.ConnectionStrings["AdventureWorks"].ToString();
            IDbConnection connection = new SqlConnection(conn);
            connection.Open();

            return connection;
       }
   }
}

And last but not least, here is the error:

System.Data.SqlClient.SqlException: A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)

----> System.ComponentModel.Win32Exception : No process is on the other end of the pipe


Solution

  • You have not entered any credentials in the connection string, nor are you using windows authentication it seems.

    Either use windows authentication:

    "data source=Desktop;initial catalog=AdventureWorksLT2008R2;Integrated Security=true"
    

    Or specify an SQL user with login permissions:

    "data source=Desktop;initial catalog=AdventureWorksLT2008R2;UID=myUser;PWD=myPass"
    

    For even more connectionstring goodness, see msdn. Trusted_Connection=yes might be required too.