App_Data - Why oh why are you there?!!
Posted by (JavaScript must be enabled to view this email address) on Wed 18 Mar 2009
On deploying a site for a customer we were presented with all sorts of ASP.Net errors. First I was told that the database was the incorrect type (i.e. the app thought it was SQL Express edition instead of the SQL Standard Edition).
provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified”
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) +4844759
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4858065
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +376
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +4859187
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +87
System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +221
System.Web.Security.SqlRoleProvider.GetRolesForUser(String username) +760
System.Web.Security.RolePrincipal.IsInRole(String role) +164
System.Web.SiteMapProvider.IsAccessibleToUser(HttpContext context, SiteMapNode node) +202
System.Web.SiteMapNode.IsAccessibleToUser(HttpContext context) +17
System.Web.StaticSiteMapProvider.GetChildNodes(SiteMapNode node) +356
System.Web.SiteMapNode.get_ChildNodes() +27
System.Web.SiteMapNode.get_HasChildNodes() +7
System.Web.SiteMapNode.System.Web.UI.IHierarchyData.get_HasChildren() +7
System.Web.UI.WebControls.Menu.DataBindRecursive(MenuItem node, IHierarchicalEnumerable enumerable) +3042
System.Web.UI.WebControls.Menu.DataBindItem(MenuItem item) +231
System.Web.UI.WebControls.Menu.PerformDataBinding() +50
System.Web.UI.WebControls.HierarchicalDataBoundControl.PerformSelect() +85
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.Menu.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.Menu.EnsureDataBound() +40
System.Web.UI.WebControls.Menu.CreateChildControls() +107
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +44
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
To resolve the issue I started looking at my database; you’d think that was the obvious place or not? I restored my database, that didnt work, I attached my MDF files, that didnt work, finally I even tried to build the database entirely using SQL Scripts; but still the app was telling me that the database was a SQL Express Schema.
In desperation, I searched my code for any references to .MDF which I may have had…nothing; I searched for connection strings - no luck there either! What was going on?
Eventually - for no reason other than to try attaching the .MDF file again; I did a file search on my dev machine and found that there was an ASPNET.MDF file present in the app_data folder. Now, this shouldn’t be there, I was using my own database for roles based authentication. So I deleted it. Redeployed my site; and again was told there was no database…
I gave up on the host; clearly they were going to be no help so I set about replicating the environment on our own servers. I set up the site; configured role memberships and disabled custom errors…on browsing the site; I was able to find out that the ASPNET user was trying to create a database in the App_Data folder; I have no idea why; so yet again I searched through all my source for any reference to App_Data that was there. Nothing. Absolutely no references. So I deleted the Folder.
As soon as I hit CTRL-F5 the site worked…could this have been the error? All my problems seemed to have been caused by the ASPNET worker process trying to create a database in the App_Data folder even though it was never used.
I have yet to fathom out why ASP.Net decides to create a database in the APP_Data folder; but if its causing you problems you simply need to delete the folder (as long as you arent using it).
Your Comments
Commenting is not available in this section entry.