简体   繁体   English

System.Data.EntityException:基础提供程序在打开时失败

[英]System.Data.EntityException: The underlying provider failed on Open

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. 它在服务器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? 有人知道为什么会这样吗?

I just use 我只是用

 IntegratedSecurity = true,

to

 IntegratedSecurity = false,

and it works! 而且有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ System.Data.EntityException”的第一次机会异常。 基础提供程序在打开时失败 - First chance exception of 'System.Data.EntityException'. The underlying provider failed on Open System.Data.Entity.Core.EntityException:“基础提供程序在打开时失败。” 错误? - System.Data.Entity.Core.EntityException: 'The underlying provider failed on Open.' Error? EntityException:底层提供程序在Open +内部异常上失败 - EntityException: The underlying provider failed on Open + inner exceptions 未处理EntityException基础提供程序无法打开 - EntityException was unhandled the underlying provider failed to open 用户代码未处理System.Data.EntityException - System.Data.EntityException was unhandled by user code System.Data.EntityException”发生在System.Data.Entity.dll中 - System.Data.EntityException' occurred in System.Data.Entity.dll 系统数据实体。 基础提供程序在打开时失败 - System Data Entity. The underlying provider failed on Open 标的提供商无法开放 - The Underlying Provider Failed to open 错误:基础提供程序在打开时失败。 用户的system.data.sqlclient.sqlexception登录失败 - Error: the underlying provider failed on open. system.data.sqlclient.sqlexception login failed for user 基础提供程序在打开时失败 - The underlying provider failed on Open
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM