1

ASP.NET MVC 4 アプリケーションを IIS 7 にデプロイしましたが、参照すると次のエラーが表示されます。

Cannot open database "PCSPI" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.

そして、アプリケーション プール ID を networkService に変更すると、次のようになります。

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'WORKGROUP\OSCAR-PC$'.    
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "PCSPI" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.

Source Error: 


Line 23: 
Line 24:             //* Role initialization method
Line 25:             WebSecurity.InitializeDatabaseConnection(
Line 26:                 "DatabaseConnection",
Line 27:                 "UserProfile",

Source File: c:\Users\OSCAR\Documents\Visual Studio 2012\Projects\PCSPI\WebUI\Global.asax.cs    Line: 25 

Stack Trace: 


[SqlException (0x80131904): Cannot open database "PCSPI" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +6675286
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +688
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4403
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +84
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +55
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +368
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +6703926
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +6704427
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) +610
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1049
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +74
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) +6706995
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) +78
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +2192
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1012
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6711619
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +152
   System.Data.SqlClient.SqlConnection.Open() +229
   WebMatrix.Data.Database.EnsureConnectionOpen() +115
   WebMatrix.Data.<QueryInternal>d__0.MoveNext() +79
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +247
   WebMatrix.WebData.SimpleMembershipProvider.CheckTableExists(IDatabase db, String tableName) +90
   WebMatrix.WebData.SimpleMembershipProvider.CreateTablesIfNeeded() +64
   WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables) +95
   WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +86
   WebUI.MvcApplication.Application_Start() in c:\Users\OSCAR\Documents\Visual Studio 2012\Projects\PCSPI\WebUI\Global.asax.cs:25

[HttpException (0x80004005): Cannot open database "PCSPI" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12864673
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Cannot open database "PCSPI" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601

しかし、アプリケーション プールの ID を変更すると、IIS が SQL Server へのアクセスに使用するログインが変更されるため、SQL Server の問題でネットワーク サービスへのアクセスを許可する必要があることがわかりました。

どうすれば networkService へのアクセスを許可できますか?

どんな助けでも大歓迎です、事前に感謝します

4

2 に答える 2

4

おそらく、ネットワーク サービスではなくシステム アカウントを使用していたことに注意してください。「NT AUTHORITY\SYSTEM」はネットワーク サービス アカウントではありません。

Security -> Logins に移動し、次のような新しいログインを作成します。次に、ネットワーク サービスのユーザー マッピングを設定して、必要な権限のみを持つようにします。

ここに画像の説明を入力

于 2013-05-09T08:18:29.237 に答える
3

SQL Server は IIS と同じサーバーにありますか? その場合は、SSMS (SQL Server Management Server) に移動し、「NT AUTHORITY\NETWORK SERVICE」ログイン アクセスを許可します。

SQL Server が別のサーバーにある場合は、別のアカウントまたは SQL Server ログインを使用する必要があります。

于 2013-05-09T00:29:46.503 に答える