System.Data.EntityException: The underlying provider failed on Open

c# entity-framework sql-server-2008-r2 winforms

Question

I am building an application which has a database on the server machine and I am using this method for database access:

public static string GetDefaultConnectionString()
{
    //get my db info from ini file
    dbinfo DatabaseInfo = new dbinfo();
    DatabaseInfo = GetDatabaseInfo();
    if (DatabaseInfo.dbName == "" || DatabaseInfo.Password == "" || DatabaseInfo.Server == "" || DatabaseInfo.UserId == "")
    {
        throw new Exception("Database config file is not valid");
    }
    else
    {
        MessageBox.Show("Db name " + DatabaseInfo.dbName);
        MessageBox.Show("User " + DatabaseInfo.UserId);
        MessageBox.Show("Db Pass " + DatabaseInfo.Password);
        MessageBox.Show("Db Server " + DatabaseInfo.Server);
    }
    string conStrIntegratedSecurity = new System.Data.EntityClient.EntityConnectionStringBuilder
    {
        Metadata = "res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl",
        Provider = "System.Data.SqlClient",
        ProviderConnectionString = new System.Data.SqlClient.SqlConnectionStringBuilder
        {
            InitialCatalog = DatabaseInfo.dbName,
            DataSource = DatabaseInfo.Server,
            IntegratedSecurity = true,
            UserID = DatabaseInfo.UserId,
            Password = DatabaseInfo.Password,
            MultipleActiveResultSets = true,
            ConnectTimeout = 0,
            MaxPoolSize = 500,
        }.ConnectionString
    }.ConnectionString;
    //MessageBox.Show(conStrIntegratedSecurity);
    return conStrIntegratedSecurity;
}

and it works fine in server pc. But, when I install this application on any client machine, it cannot open a connection and it gives the following error message:

System.Data.EntityException: The underlying provider failed on Open. ---> 
System.Data.SqlClient.SqlException: Cannot open database "dbName" requested by the login. The login failed.
Login failed for user 'ServerName\User'.

Does anyone know why this is happening?

1
1
7/17/2014 12:24:12 AM

Accepted Answer

I just use

 IntegratedSecurity = true,

to

 IntegratedSecurity = false,

and it works!

1
4/13/2014 9:52:24 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow