System.Data.EntityException:基础提供程序在打开时失败 [英] System.Data.EntityException: The underlying provider failed on Open
本文介绍了System.Data.EntityException:基础提供程序在打开时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个在服务器计算机上具有数据库的应用程序,并且正在使用这种方法进行数据库访问:
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;
}
,它在服务器PC中可以正常工作。
但是,当我在任何客户端计算机上安装此应用程序时,它无法打开连接,并显示以下错误消息:
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?
推荐答案
我只使用
IntegratedSecurity = true,
到
IntegratedSecurity = false,
它有效!
这篇关于System.Data.EntityException:基础提供程序在打开时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文