0

I keep getting the following error when trying to access a particular webpage.

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

When I go into IIS and configure the directory as an application, as the error states I should do, the page seems to await a response, and shows a blank white page, for about 1-2 minutes, then I get the following error:

 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

The SQL Server is up and is accessible to all other pages on the site. I have been trying to troubleshoot this error for many hours a day for about a week now with no success. I am new to IIS, and I cannot think of other things to try at this point. I was wondering if someone can help me identify the cause of this error. This particular page was loading and working fine about 2 weeks ago.

2 Answers 2

2

It looks like that what ever you are doing on that page can't access to SQL Server. How do you connect to database ? Using Windows Authentication or using SQL Server Login ? Do you use impersonation in IIS ? I would guess for example, you are tying to run some SP and this user doesn't have permission to run SP.

Can you check Database Connection accessibility (and availability) using database connection manager in IIS ? This IIS help shows how to do that.

4
  • Thanks for the reply. Using windows authentication. This is connection string I am using in the webconfig file: <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="50" /> Mar 1, 2013 at 16:41
  • What do you see in Database Manager ?
    – JackLock
    Mar 1, 2013 at 16:58
  • The screenshot is of SSMS (SQL Server Management Studio), I am interested in Database Manager. My original answer has a help link about where to find Database Manager in IIS.
    – JackLock
    Mar 1, 2013 at 17:27
  • Oh sorry, I am working on that right now, will check back when I get it. Mar 1, 2013 at 17:37
1

You should definitely leave the virtual directory as an application.

The SQL error is likely something wrong with the connection string.

You said that other pages work...Is there a standard way that all your pages connect to SQL? Do they all take the connection string from the web.config? Or is it hard coded on the page?

4
  • Thanks for the reply. They take the connection string from the web.config file. This is connection string: <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="50" /> Mar 1, 2013 at 16:43
  • That's the connection string for session state. We need the other connection string. It's either in the <appSettings> or the <connectionStrings> section depending on your .NET version. Try searching for ";database" in your web.config file
    – basher
    Mar 1, 2013 at 16:50
  • Search for ;database returned no results in the web.config file. Mar 1, 2013 at 17:23
  • How do your other pages connect to SQL?
    – basher
    Mar 1, 2013 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.