简体   繁体   English

ASP.net网站将LocalDB部署到IIS7

[英]ASP.net website with LocalDB deployment to IIS7

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. 我在Visual Studio 2012 Ultimate中开发了一个ASP.net网站(C#)。 I created the App_Data folder and created a SQL Sever Database. 我创建了App_Data文件夹并创建了一个SQL Sever数据库。 When all the development was done, I decided to deploy the website to IIS7 on Windows Server 2008 R2. 所有开发完成后,我决定将网站部署到Windows Server 2008 R2上的IIS7。 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 我在IIS中选择了.Net FrameWork版本到v4.0

This is the error I am getting when accessing the pages with a gridview for example. 这是我在使用gridview访问页面时遇到的错误。

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! 感谢您的帮助!

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. [SqlException(0x80131904):建立与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. 验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (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.)] (提供程序:SQL网络接口,错误:52 - 无法找到本地数据库运行时安装。验证是否已正确安装SQL Server Express并且已启用本地数据库运行时功能。)]

LocalDB (SQL Database inside App_Data) is primarily intended for developing and testing purpose only. LocalDB (App_Data中的SQL数据库)主要用于开发和测试目的。 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. 当您的应用程序生效时,您需要一个真正的SQL Server。 So you need to install SQL Server either in the same server that the application is hosted or a dedicated SQL server. 因此,您需要在托管应用程序的同一服务器或专用SQL服务器上安装SQL Server。 Then attach that database. 然后附加该数据库。

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. 仍然必须在计算机上安装LocalDB才能使其正常工作,它不是自动包含在应用程序部署中的免费SQL Server版本。 On your local workstation, LocalDB was installed when you installed Visual Studio. 在本地工作站上,安装Visual Studio时安装了LocalDB。

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. LocalDB应由开发人员在本地使用,因此在服务器情况下,您可能需要查看SQL Server Express。

You need to set a value in appPool config to enable your site to reach your .mdf file: 您需要在appPool配置中设置一个值,以使您的网站能够访问.mdf文件:

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

set etProfileEnvironment=“true“ like that: 像这样设置etProfileEnvironment =“true”:

<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/ https://blogs.msdn.microsoft.com/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-1-user-profile/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM