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,Action`1 wrapCloseInAction) +5296071 System.Data.sqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,Boolean callerHasConnectionLock,Boolean asyncClose) +558 System.Data.sqlClient.TdsParser.Connect(ServerInfo serverInfo,sqlInternalConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,Boolean encrypt,Boolean trustServerCert,Boolean integratedSecurity,Boolean withFailover) +5308555 System.Data.sqlClient.sqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,SecureString newSecurePassword,TimeoutTimer timeout,Boolean withFailover) +145 System.Data.sqlClient.sqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,Boolean redirectedUserInstance,sqlConnectionString connectionOptions,sqlCredential credential,TimeoutTimer timeout) +920 System.Data.sqlClient.sqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout,Boolean redirectedUserInstance) +307 System.Data.sqlClient.sqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,Object providerInfo,sqlConnectionString userConnectionOptions) +434 System.Data.sqlClient.sqlConnectionFactory.CreateConnection(DbConnectionOptions options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool pool,DbConnection owningConnection,DbConnectionOptions userOptions) +5311099 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool,DbConnectionOptions options,DbConnectionOptions userOptions) +37 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) +558 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) +67 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal& connection) +1052 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource`1 retry,DbConnectionInternal& connection) +78 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,DbConnectionInternal& connection) +167 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,DbConnectionOptions userOptions) +143 System.Data.sqlClient.sqlConnection.TryOpen(TaskCompletionSource`1 retry) +83 System.Data.sqlClient.sqlConnection.Open() +96 Default.log(Object sender,EventArgs e) in c:\users\sreekanth\documents\visual studio 2010\Projects\IPCWebApp\IPCWebApp\Default.aspx.cs:43 System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +124 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +1724
解决方法
>尝试使用管理工作室从服务器连接sql server。如果使用Windows身份验证连接sql server,则将应用程序池标识设置为服务器管理员。
>如果您使用sql server身份验证,那么请检查web应用程序的web.config中的连接字符串,并设置允许您登录的sql server的用户名和密码。
>如果您的数据库在其他服务器(访问远程数据库)中,则首先启用sql server的远程访问,从sql server management studio启动sql server属性,并启用TCP / IP表单sql server配置管理器。
>在完成所有这些内容后,您仍然无法访问数据库,然后检查要尝试访问数据库的服务器窗体的防火墙,并在防火墙中添加一个规则以启用sql server的端口(默认情况下,sql server使用1433,to检查sql server的端口,需要检查sql server配置管理器的网络协议TCP / IP端口)。
>如果您的sql server在命名实例上运行,则需要使用sql serer名称写入端口号,例如117.312.21.21/nameofsqlserver1433。
>如果您正在使用像amazon aws或microsoft azure这样的云托管服务器或实例将运行在云端防火墙后面,因此如果您有命名实例的sql server的默认实例或特定端口,则需要在云端防火墙中启用1433端口。
>如果您使用的是亚马逊RDS或sql azure,则需要从该实例的安全组启用端口。
>如果您通过sql server身份验证模式访问sql server,请确保启用了“sql Server和Windows身份验证模式”sql server instance属性。
>在对属性进行任何更改后重新启动sql server实例,因为某些更改将需要重新启动。
如果您进一步面对任何困难,那么您需要提供有关您的网站和sql服务器的更多信息。