2012-04-03 19 views
1

我有一個我正在構建的MVC3/EF4.1應用程序,現在可以在我的本地機器上正常工作,但僅在生產環境(WinHost中的虛擬主機)中存在特定問題。我看到的錯誤是「SQL網絡接口,錯誤:26 - 錯誤定位服務器/實例指定」通常意味着連接字符串問題,或者有時SQLEXPRESS(我正在使用SQL 2008 R2)不是您想要使用的。我看着周圍很多,並試圖使用錯誤此綜合說明,以及:SQL網絡接口錯誤:26,但不是連接字符串,它是Entity Framework嗎?

http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx

我能夠登錄到生產現場;另外,當我有目的地使用錯誤的密碼等時,我得到驗證錯誤。這使我認爲數據庫的連接字符串必須正常。登錄頁面由Microsoft在項目啓動時生成。但是,一旦我移動到自那時以來,我已經添加了網頁(使用EF),其中與數據庫的連接是必需的,然後我得到以下錯誤(例如索引頁房源的記錄。):

Server Error in '/' Application. 
-------------------------------------------------------------------------------- 

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) 
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: 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) 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[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.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064522 
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234 
    System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) +341 
    System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +129 
    System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +270 
    System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195 
    System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232 
    System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185 
    System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33 
    System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524 
    System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 
    System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479 
    System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108 
    System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126 
    System.Data.SqlClient.SqlConnection.Open() +125 
    System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +52 

[EntityException: The underlying provider failed on Open.] 
    System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +161 
    System.Data.EntityClient.EntityConnection.Open() +98 
    System.Data.Objects.ObjectContext.EnsureConnection() +81 
    System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +46 
    System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +44 
    System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator() +40 
    System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +40 
    System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +315 
    System.Linq.Enumerable.ToList(IEnumerable`1 source) +58 
    MySite.Controllers.ContactController.Index() in ContactController.cs:25 
    lambda_method(Closure , ControllerBase , Object[]) +40 
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17 
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +188 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27 
    System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +267 
    System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +20 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190 
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +329 
    System.Web.Mvc.Controller.ExecuteCore() +115 
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +94 
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 
    System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37 
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21 
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55 
    System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31 
    System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7 
    System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8969201 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 

-------------------------------------------------------------------------------- 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272 

我究竟做錯了什麼?如果它不是連接字符串(基於我的假設),那麼爲什麼會得到這個錯誤?我還需要發佈其他哪些代碼才能解決這個謎團?提前致謝。

+0

我有我的WinHost運行,與SQL 2008 R2數據庫nopCommerce網站,並沒有任何問題覆蓋的敏感數據。 – 2012-04-03 18:08:16

回答

0

我想我已經弄明白了,希望這可以幫助任何人在相同的情況下。

我認爲發生的事情是EF4.1在Web.config中引入了一個Entities項目,該項目有一個自己的連接字符串。當然,我已經有了自己的連接字符串。問題在於應用程序的不同部分使用了不同的連接字符串。所以,安全/登錄使用了一個很好的連接字符串,而各種自定義頁面試圖使用實體連接字符串(並失敗,因爲實體的未更改連接字符串指向我本地驅動器上的某處)。

我做了一個古老的蠻力方法來建立一個新的(空)項目,並添加奇異的東西,直到破產。在這種情況下,實體(或缺乏)打破了應用程序,這讓我更密切地關注它。

以下是更正之一,由*的

<add name="MySiteEntities" connectionString="metadata=res://*/Models.MySite.csdl|res://*/Models.MySite.ssdl|res://*/Models.MySite.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=******;Initial Catalog=*******;User ID=******;Password=****;Integrated Security=False;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
+0

嘿,所以我開始gthe同樣的問題。但它是這個錯誤大吼我:System.Data.MetadataException:無法加載指定的元數據資源。 「你偶然發現了這個錯誤嗎?」 – gdubs 2012-05-30 19:00:06

+0

嗯,不,我沒有看到,我建議發佈一個新的問題,並提供詳細信息(如果你喜歡,請附上這個鏈接),看看我們能否得到一些幫助我的大部分問題都很快得到了Stack上有用的社區的迴應。 – 2012-05-30 22:21:43

相關問題