asp.net - 与 SQL Server 建立连接时发生与网络相关或特定于实例的错误

标签 asp.net sql-server sql-server-2008 database-connection connection-string

很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .




9年前关闭。




我在 somee.com 上部署了我的 asp.net Web 应用程序,每当我登录该站点 (ipc.somee.com) 时,它都会给我一个与网络相关的错误,例如:

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, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +920
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, 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, DbConnectionPoolKey poolKey, 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, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +167
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, 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 会触发此错误。这个错误有几个原因。要修复此错误,您应该按照以下说明进行操作。

  • 尝试使用 management studio 从您的服务器连接 sql server。如果您使用 Windows 身份验证连接 sql server,则将您的应用程序池身份设置为服务器管理员。
  • 如果您使用 sql server 身份验证,请检查您的 web 应用程序的 web.config 中的连接字符串,并设置允许您登录的 sql server 的用户 ID 和密码。
  • 如果您的数据库在其他服务器中(访问远程数据库),那么首先从 sql server management studio 启用远程访问 sql server form sql server property 并启用 TCP/IP form sql server configuration manager 。
  • 在做完所有这些事情之后,您仍然无法访问数据库然后检查您尝试访问数据库的服务器形式的防火墙并在防火墙中添加一条规则以启用 sql server 的端口(默认情况下 sql server 使用 1433 ,检查sql server 的端口,你需要检查 sql server 配置管理器网络协议(protocol) TCP/IP 端口)。
  • 如果您的 sql server 在命名实例上运行,那么您需要使用 sql serer 名称编写端口号,例如 117.312.21.21/nameofsqlserver,1433。
  • 如果您使用的是 amazon aws 或 microsoft azure 等云托管,那么服务器或实例将在云防火墙后面运行,因此如果您有默认实例或命名实例的 sql server 特定端口,则需要在云防火墙中启用 1433 端口。
  • 如果您使用的是 amazon RDS 或 SQL azure,则需要从该实例的安全组启用端口。
  • 如果您通过 sql server 身份验证模式访问 sql server,请确保您启用了“SQL Server 和 Windows 身份验证模式”sql server 实例属性。
    enter image description here
  • 在对属性进行任何更改后重新启动您的 sql server 实例,因为某些更改需要重新启动。

  • 如果您进一步遇到任何困难,那么您需要提供有关您的网站和 sql server 的更多信息。

    关于asp.net - 与 SQL Server 建立连接时发生与网络相关或特定于实例的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16256533/

    相关文章:

    sql-server - 为什么 Pivot 给出的错误为 'Incorrect syntax near ' 4721'

    sql-server-2008 - 寻找具有动态列的配置文件表的 SQL Server 表设计健全性检查

    c# - 无法将 int 转换为可空 int

    sql - 恢复未保存的 SQL 查询脚本

    html - CSS 不适用于母版页

    sql-server - 当 2 列的数据匹配时选择记录

    php - 如何为提供的密码和盐复制密码哈希 (PHP/MySQL)

    sql-server-2008 - Solr DataImportHandler登录到SQL,但从不获取任何数据

    c# - 查找失败的验证器 asp.net

    asp.net - 回发期间出现“由于对象的当前状态,操作无效”错误