无法打开数据库。用户“ NT AUTHORITY \ NETWORK SERVICE”的登录失败

我正在尝试在IIS上部署我的第一个ASP.NET应用程序,但是无论何时连接到数据库,我都面临一个问题。连接到数据库可以在Visual Studio上很好地运行应用程序。

我不断收到以下信息:

SqlException: Cannot open database "RazorPagesMovieContext-ae4522b8-14f6-4dd9-9e71-fb8009d965ad" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.

我的连接字符串如下所示:

<add connectionString="Server=(localdb)\MSSQLLocalDB;Database=RazorPagesMovieContext-ae4522b8-14f6-4dd9-9e71-fb8009d965ad;Integrated Security=true" name="LocalSqlServer" providerName="System.Data.SqlClient" />

Like stated in the article here: https://docs.microsoft.com/en-us/archive/blogs/sqlexpress/using-localdb-with-full-iis-part-2-instance-ownership I have tried #1 "Run IIS as our Windows user" and #2 "Use LocalDB Shared Instance" of the approaches without any luck so I've moved to trying NetworkService instead of ApplicationPoolIdentity which is where I'm facing the same error(using ApplicationPoolIdentity fails with "Login failed for user 'IIS APPPOOL.NET v4.5'") just under different user.

在我的SQL Server Management Studio上,我创建了一个新用户,名称为“ NT AUTHORITY \ NETWORK SERVICE”,并确保已授予数据库“ db owner”权限,并勾选了所有“服务器角色”。大多数答案都指向授予权限,但这仍然无法解决我的问题。

任何见解将不胜感激

评论