2

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

Mackan
  • 6,200
  • 2
  • 25
  • 45
alphamalle
  • 192
  • 1
  • 3
  • 15
  • http://stackoverflow.com/questions/21352229/sql-exception-no-process-is-on-the-other-end-of-the-pipe Have you tried all things listed in the answer? – Mackan Apr 28 '15 at 07:28
  • I did. I actually stumbled across that in my search and had no luck. – alphamalle Apr 28 '15 at 10:21

1 Answers1

0

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.

Mackan
  • 6,200
  • 2
  • 25
  • 45
  • I have tried several different security types, but have not tried this one yet. I've even entered in userid and password. I will attempt this, and report back when I get home from work. Thanks for your help. – alphamalle Apr 28 '15 at 10:20
  • 1
    This is the correct solution thanks so much. I only needed to add Integrated Security=true into my connection string. – alphamalle Apr 28 '15 at 20:32