如何修复System.Data.SqlClient.SqlException:“用户"xx \ xxxx $"的登录失败; [英] How to fix System.Data.SqlClient.SqlException : "Login failed for user "xx\xxxx$""

查看:119
本文介绍了如何修复System.Data.SqlClient.SqlException:“用户"xx \ xxxx $"的登录失败;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IIS上运行了一个Web应用程序,并且获得了

I ran a web app on IIS and I got a

System.Data.SqlClient.SqlException: "Login failed for user'domain\account$'".

当调用函数 DbMigrator.Update()时,这是一个例外情况

This is a exception when the function DbMigrator.Update() is called

private readonly DbMigrationsConfiguration<MyContext> _config;
public ContextInitializer(string connectionString)
{
    _config = new Configuration()
    {
        TargetDatabase = new DbConnectionInfo(connectionString, "System.Data.SqlClient")
    };
}
...

public void InitializeDatabase(MgmtStudioContext context)
{
    var migrator = new DbMigrator(_config);
    migrator.Update();
}

这是堆栈跟踪:

at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)\r\n   
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)\r\n  
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)\r\n  
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)\r\n   
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)\r\n   
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)\r\n   
at System.Data.SqlClient.SqlConnection.Open()\r\n   
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)\r\n   
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)\r\n   
at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()\r\n   
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()\r\n   
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)\r\n   
at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)\r\n   
at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)\r\n   
at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)\r\n   
at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)\r\n   
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)\r\n   
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)\r\n   at 

这是我的连接字符串:

Data Source=(local);Initial Catalog=myTable; Integrated Security=True;

该代码在其他计算机上也可以正常工作,但是在我的计算机上不起作用,并且我无法找到根本原因.

The code works fine in other machine, but in my computer it doesn't work and I can't find out the root cause.

推荐答案

根据错误消息,帐户"domain \ account $"无权访问myTable数据库.

According to the error message, the account 'domain\account$' does not have access to the myTable database.

我建议您首先可以使用SQL Server管理系统的安全性来检查他的帐户"domain \ account $"没有访问(本地)服务器的myTable数据库的权限.

I suggest you could firstly use the SQL server management system's security to check he account 'domain\account$' does not have access to the (local) server's myTable database.

更多详细信息,您可以参考此答案.

More details, you could refer to this answer.

更新:

据我所知,是否要使用Windows Integrated Security访问SQL Server.首先,应确保IIS服务器和sql服务器位于同一intranet内,并使用同一域.

As far as I know, if you want to access SQL Server Using Windows Integrated Security. You should firstly make sure your IIS server and the sql server is inside the same intranet and use the same domain.

然后,我建议您确保设置了正确的应用程序池标识帐户,该帐户具有访问sql数据库的权限.

Then I suggest you could make sure you have set the right application pool identity account which has the permission to access the sql database.

1.您应该在sql server中使用域帐户"domain \ account",以确保它具有读写权限

1.You should the domain account "domain\account" in sql server to make sure it has the read and write permission

2.在IIS上,打开应用程序池"设置.对于身份"选项,选择自定义帐户".输入您的用户名域\帐户)和密码.

2.On IIS, open Application Pool settings.For Identity option, choose "Custom Account". Enter your username domain\account) and password.

然后它会很好地工作.

这篇关于如何修复System.Data.SqlClient.SqlException:“用户"xx \ xxxx $"的登录失败;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆