![](/img/trans.png)
[英]Login failed for user error when connecting to SQL Server during Excel import
[英]Login Failed Error when connecting to SQL Server
我无法连接到我们工作服务器上的数据库之一。 能够连接到一个数据库但不能连接到另一个(都托管在同一台服务器上)。 通过 C#.Net Framework 应用程序连接。 这是设置。
//connection string for mydb1:
string connectionString1 = "Data Source=MYSQLSERVER;Initial Catalog=mydb1;Integrated Security=SSPI" //(able to connect to mydb1)
//connection string for mydb2:
string connectionString2 = "Data Source=MYSQLSERVER;Initial Catalog=mydb2;Integrated Security=SSPI" //(unable to connect to mydb2)
//Connect and open mydb1:
using (SqlConnection connection = new SqlConnection(connectionString1))
{
SqlCommand command = new SqlCommand("SELECT TOP 10 * FROM sometable", connection);
command.Connection.Open(); //Success
}
//Connect and open mydb2:
using (SqlConnection connection = new SqlConnection(connectionString2))
{
SqlCommand command = new SqlCommand("SELECT TOP 10 * FROM sometable", connection);
command.Connection.Open(); //Failure
}
对于 myDb2 错误日志有这样的:
System.Data.SqlClient.SqlException (0x80131904):无法打开登录请求的数据库“mydb2”。 登录失败。
用户“用户”登录失败错误号:4060,State:1,Class:11
我的猜测是问题不在于代码,而在于 mydb2 的 SQL 服务器中的某种设置(因为我能够使用完全相同的连接字符串设置连接到 mydb1)。
我在 SQL Server Management Studio 中检查了“连接属性”(右键单击 db > 属性 > 查看连接属性),并且在身份验证 > 身份验证方法下都具有“Windows 身份验证”,并且用户名设置为我的用户名。 此连接属性下的所有其他设置在 mydb1 和 mydb2 之间也是完全相同的。
我是 SQL 服务器的初学者,尤其是使用身份验证设置。
任何指导表示赞赏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.