0

尝试访问特定网页时,我不断收到以下错误。

allowDefinition='MachineToApplication'使用注册为超出应用程序级别的部分是错误的。此错误可能是由未在 IIS 中配置为应用程序的虚拟目录引起的。

当我进入 IIS 并将目录配置为应用程序时,正如我应该做的错误状态,页面似乎在等待响应,并显示一个空白页面,大约 1-2 分钟,然后我收到以下错误:

 Server Error in '/inventory' 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +6256377
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +6270399
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +181
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +6271242
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +6271208
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +354
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +703
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +54
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +6272472
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +81
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +1657
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +88
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6275911
   System.Data.SqlClient.SqlConnection.Open() +258
   Inventory1.welcome.Page_Load(Object sender, EventArgs e) +219
   System.Web.UI.Control.OnLoad(EventArgs e) +132
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

SQL Server 已启动并可访问站点上的所有其他页面。我一直在尝试解决这个错误好几个小时,现在已经持续了大约一周,但没有成功。我是 IIS 新手,目前我想不出其他可以尝试的方法。我想知道是否有人可以帮助我确定此错误的原因。这个特定页面大约在 2 周前加载并正常工作。

4

2 回答 2

2

看起来您在该页面上所做的任何事情都无法访问 SQL Server。你如何连接到数据库?使用 Windows 身份验证还是使用 SQL Server 登录?您在 IIS 中使用模拟吗?例如,我猜想,您要运行某个 SP,而该用户没有运行 SP 的权限。

您可以使用 IIS 中的数据库连接管理器检查数据库连接的可访问性(和可用性)吗?此 IIS 帮助显示了如何执行此操作。

于 2013-03-01T15:52:46.997 回答
1

您绝对应该将虚拟目录保留为应用程序。

SQL 错误可能是连接字符串有问题。

您说其他页面可以工作...是否有一种标准方式可以让您的所有页面都连接到 SQL?他们都从 web.config 中获取连接字符串吗?还是在页面上硬编码?

于 2013-03-01T16:00:21.420 回答