Error opening connection to SQL Server 2008 R2 database

Asked

Viewed 1,631 times

1

I’m having a problem opening a connection to a local database in SQL Server 2008 R2.

The opening method that is giving error is as follows:

public static SqlConnection AbreConexao()
{
    string path = System.IO.Directory.GetCurrentDirectory();

    _DataSource = INI.LerINI(@path + "\\ConfigDB.ini", "DataSource");
    _InitialCatalog = INI.LerINI(@path + "\\ConfigDB.ini", "InitialCatalog");
    _UserId = INI.LerINI(@path + "\\ConfigDB.ini", "UserId");
    _Password = INI.LerINI(@path + "\\ConfigDB.ini", "Password");

    connString = "Data Source=" + _DataSource + ";Initial Catalog=" + _InitialCatalog + ";User Id=" + _UserId + ";Password=" + _Password + "";            

    conn = new SqlConnection(connString);

    try
    {
        conn.Open();
    }
    catch (SqlException ex)
    {
        conn = null;
        MessageBox.Show(ex.Message);
        Application.Exit();
    }

    return conn;
}

Connectionstring is like this:

'Data Source=ADMIN;Initial Catalog=ControleFinanceiro;User Id=Admin\User;Password='

At the moment of opening the connection it shows the following error:

"A connection to the server was successfully established, but a error during logon process. (Preview: Shared Memory Provider, error: 0 - No process at the other end of the pipe.)"

I have already released the protocols in SQL Configuration Manager for TCP/IP, Namedpipes and Shared Memory.

Allow remote connections check in the DB connection configuration is also enabled.

Does anyone have any ideas to solve?

  • Within SQL Server Configuration Manager, in Client Protocols you have the option to change the order of connection, try to put TCP/IP first, and check if SQL Server is configured for mixed connection, check out this connection string.

  • TCP/IP is always in second, first the Shared Memory (It is only possible to take the Shared Memory of the first order disabling, I did the test like this and the error persisted), SQL is yes configured for mixed connection.

1 answer

2

This Exception usually appears when the specified database or user is misspelled or when the database does not actually exist.

I also use the following Connection string format.

Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername; Password=myPassword;

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.