2017-07-19 33 views
-1

好吧,所以我有這個MVC5網站,使用聲明標識。OWIN - '/'應用程序中的服務器錯誤

OWIN拋出這個討厭的錯誤:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

如果我手動刪除的 'bin' 的一切, 'OBJ' 文件夾,網站工作。

問題是,我也在部署中不時發現此錯誤。

SQL Server很好,工作100%。 這是從OWIN別的東西,造成這種情況。

我記得過去有過這個問題,但我記不清我做了什麼來解決它。

下面是完整的堆棧跟蹤:

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +1385
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1091
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +70
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +981
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +114
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1590
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +156
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +268
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1 retry, DbConnectionOptions userOptions) +314
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource
1 retry) +204
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1 retry) +245 System.Data.SqlClient.SqlConnection.Open() +130
System.Data.Entity.Infrastructure.Interception.InternalDispatcher
1.Dispatch(TTarget target, Action 2 operation, TInterceptionContext interceptionContext, Action 3 executing, Action 3 executed) +98
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +509
System.Data.Entity.SqlServer.<>c__DisplayClass33.<UsingConnection>b__32() +566 System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +15
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func
1 operation) +237
System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action 1 act) +913
System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable
1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript) +117
System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable 1 commandTimeout, StoreItemCollection storeItemCollection) +211
System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection) +134
System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +174
System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) +116
System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func
3 createMigrator, ObjectContext objectContext) +121 System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +292
System.Data.Entity.CreateDatabaseIfNotExists 1.InitializeDatabase(TContext context) +187
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +71
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +482 System.Data.Entity.Internal.RetryAction
1.PerformAction(TInput input) +174
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action 1 action) +273
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +38
System.Data.Entity.Internal.Linq.InternalSet
1.Initialize() +77
System.Data.Entity.Internal.Linq.InternalSet 1.get_InternalContext() +21 System.Data.Entity.Internal.Linq.InternalSet 1.FindAsync(CancellationToken cancellationToken, Object[] keyValues) +69
System.Data.Entity.DbSet 1.FindAsync(CancellationToken cancellationToken, Object[] keyValues) +46
System.Data.Entity.DbSet
1.FindAsync(Object[] keyValues) +19
Microsoft.AspNet.Identity.EntityFramework.d__6c.MoveNext() +198 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62 Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +48 Microsoft.AspNet.Identity.Owin.<b__1>d__4.MoveNext() +828 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62
Microsoft.Owin.Security.Cookies.d__2.MoveNext() +2534 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62
Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +823 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62
Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +333
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62 Microsoft.AspNet.Identity.Owin.d__0.MoveNext() +450 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62 Microsoft.AspNet.Identity.Owin.d__0.MoveNext() +450 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62 Microsoft.AspNet.Identity.Owin.d__0.MoveNext() +450 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext() +203 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__2.MoveNext() +193 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +119
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +365 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134

+0

這是一個DI問題,你沒有在每次請求後關閉連接池對象嗎? – Neil

回答

0

你可以嘗試以下...

編輯對ApplicationHost.config通常在C:\ WINDOWS \ SYSTEM32 \ INETSRV \ config並改變setProfileEnvironment爲真。

<applicationPoolDefaults managedRuntimeVersion="v4.0"> 
    <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" /> 
</applicationPoolDefaults> 
+0

謝謝你的回覆。我沒有這個文件,我從IIS Express(Visual Studio)運行它, –

0

我發現了這個問題。 Startup.cs中的這3行。

我已經評論他們,現在它相應地工作。

// Configure the db context, user manager and signin manager to use a single instance per request 
app.CreatePerOwinContext(ApplicationDbContext.Create); 
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); 
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); 
相關問題