3

First of all I would like to apologize because I have found many topics with similar problem but none solved mine.

I have developed a ASP.net website (C#) in Visual Studio 2012 Ultimate. I created the App_Data folder and created a SQL Sever Database. When all the development was done, I decided to deploy the website to IIS7 on Windows Server 2008 R2. After deployment, most of the webpages work just fine, except the ones with data from the database.

I have selected the .Net FrameWork version in IIS to v4.0

This is the error I am getting when accessing the pages with a gridview for example.

Server Error in '/' Application. The system cannot find the file 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.ComponentModel.Win32Exception: The system cannot find the file 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: [Win32Exception (0x80004005): The system cannot find the file specified] [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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)] System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +414 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 oldConnection, DbConnectionInternal& connection) +196 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +146 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +16 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +94 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +110 System.Data.SqlClient.SqlConnection.Open() +96 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121 System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +160 System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +108 dsNotificaTableAdapters.pessoasEnvolvidasTableAdapter.getPessoasEnvolvidas() +101 notificar.fillrblPessoas() +41 notificar.Page_Load(Object sender, EventArgs e) +327 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +92 System.Web.UI.Control.LoadRecursive() +54 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446 

Thanks for your help in advance!

2
  • How are you connecting to your DB? Where is it located? Is your published site pointing to it correctly? This error sounds like the published site can't find your db... Commented Jun 18, 2014 at 17:22
  • Hi @DylanCorriveau, the DB is located inside the website folder on App_Data. The webconfig file has the following: <connectionStrings> <add name="notificaConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\notifica.mdf;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> Commented Jun 18, 2014 at 17:31

3 Answers 3

2

[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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]

LocalDB (SQL Database inside App_Data) is primarily intended for developing and testing purpose only. When you publish to production, it will not be copied with your source code.

You need a real SQL Server when your application goes to live. So you need to install SQL Server either in the same server that the application is hosted or a dedicated SQL server. Then attach that database.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi @Win, I have installed SQL Server 2014 Express on my Windows Server 2008 R2. I have attached my database using sqlcmd commandline. The services SQL Server, SQL Server Browser and SQL Server VSS Writer are running. Could you please provide me further assistance to complete this task? Thank you.
Make sure you can connect to SQL Server manually using SSMS. If so, then update the connection string inside application's web.config. If you cannot connect to SQL Server using SSMS, then you need to troubleshoot the problem (a lot of questions has been asked in SO regarding that question).
I cannot see that provided error message describes something you are wrote about (i.e. "SQL Database inside App_Data is for developing/testing purpose only."). If says only that LcoalDB file not found.
@AlexG.P. I'm just explaining that LocalDB is primarily intended for developing and testing purpose only. When you publish to production, it will not be copied with your source code. Ideally, it should not be used in production environment. If you have a question, please create new one; I'll more than happy to help you.
1

LocalDB still has to be installed on the computer to make it work, it isn't a free version of SQL Server that gets included in your application deployment automatically. On your local workstation, LocalDB was installed when you installed Visual Studio.

So in the end, you still need a database server that the server running your application can connect to. LocalDB is meant to be used locally by developers, so in a server situation you may want to look into SQL Server Express.

Comments

0

You need to set a value in appPool config to enable your site to reach your .mdf file:

in C:\Windows\System32\inetsrv\config\applicationHost.config

set etProfileEnvironment=“true“ like that:

<add name=“ASP.NET v4.0“ autoStart=“true“ managedRuntimeVersion=“v4.0“ managedPipelineMode=“Integrated“> <processModel identityType=“ApplicationPoolIdentity“ loadUserProfile=“true“ setProfileEnvironment=“true“ /> </add> 

https://blogs.msdn.microsoft.com/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-1-user-profile/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.