Error opening connection to a SQL Server 2008 R2 database

-1

I have 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;
}

The ConnectionString looks like this:

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

At the time of opening the connection it displays the following error:

  

"A connection to the server was established successfully, but a   during the logon process. (provider: Shared Memory Provider,   error: 0 - There is 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.

The Allow Remote Connections check in the DB connection configuration is also enabled.

Does anyone have an idea to solve?

    
asked by anonymous 14.12.2016 / 20:35

1 answer

0

This exception usually appears when the specified database or user is spelled wrong 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 have helped.

    
30.05.2017 / 21:01