简体   繁体   English

使用LocalDB发布ASP.net网站

[英]Publishing ASP.net website With LocalDB

I'm trying to publish my website on a different computer that is on my home network. 我正在尝试将我的网站发布在家庭网络上的另一台计算机上。 I have set up IIS and SQL Server 2016 Express on that computer. 我已在该计算机上设置了IIS和SQL Server 2016 Express。 Same version on my development laptop. 我的开发笔记本电脑上的版本相同。 When I run the site I get the below error. 当我运行该网站时,出现以下错误。 I think the problem might be that I'm trying to us LocalDB. 我认为问题可能是我正在尝试使用LocalDB。 I'm often traveling and in areas where I don't have internet connectivity. 我经常旅行并且在没有互联网连接的地区。 This is why I thought it would be best to use localDB while developing. 这就是为什么我认为在开发时最好使用localDB的原因。 Once I get home I then publish to my Server. 到家后,我便将其发布到服务器上。

Originally the LocalDB was created on my computer in a folder that was far from my project. 最初,LocalDB是在我的计算机上的远离项目的文件夹中创建的。 So what I did was move it to the app_data so that it would be attached when I publish. 因此,我要做的就是将其移至app_data,以便在发布时将其附加。

What I tried: 我试过的

  1. Reinstalled Microsoft SQL Server 2016 (made sure LocalDB was installed) 重新安装了Microsoft SQL Server 2016(确保已安装LocalDB)
  2. Ensured the database was in fact in App_Data folder on server 确保数据库实际上位于服务器上的App_Data文件夹中
  3. Changed connection string to look for database in app_data 更改了连接字符串以在app_data查找数据库

Any suggestion would be great. 任何建议都很好。

Connection string: 连接字符串:

<connectionStrings 
    <add name="IgorsSellersToolBoxDB" 
         connectionString="metadata=res://*/Models.ModelDB.csdl|res://*/Models.ModelDB.ssdl|res://*/Models.ModelDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source= LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\IgorsSellersToolBoxDB.mdf;integrated security=True;multipleactiveresultsets=True;connect timeout=30;application name=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
</connectionStrings>

Error: 错误:

Server error in '/WebToolbox' Application. “ / WebToolbox”应用程序中的服务器错误。

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist. ) (提供者:SQL网络接口,错误:50-发生本地数据库运行时错误。指定的LocalDB实例不存在。)

Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 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. 异常详细信息:System.Data.SqlClient.SqlException:建立与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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.) (提供者:SQL网络接口,错误:50-发生本地数据库运行时错误。指定的LocalDB实例不存在。)

Source error: 源错误:

An unhandled exception was generated during the execution of the current web request. 当前Web请求的执行期间生成了未处理的异常。 Information regarding the origin and location of the exception can be identified using the exception stack trace below.` 可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息。

As Steve mentioned in the comments, I have confirmed that using localDB in production is frowned upon. 正如史蒂夫在评论中提到的那样,我已经确认在生产环境中使用localDB是不受欢迎的。

Solution: Use a SQL Server on my development machine and a separate one on my production server. 解决方案:在开发机器上使用一台SQL Server,在生产服务器上使用另一台SQL Server。 All I have to do is have separate connection strings in my Web.Config. 我要做的就是在Web.Config中有单独的连接字符串。

In your web.config, you can expand the file in the solution explorer, and you will see two files: 在您的web.config中,您可以在解决方案资源管理器中展开该文件,您将看到两个文件:

  • Web.Debug.Config Web.Debug.Config
  • Web.Release.Config Web.Release.Config

There is a great answer here that explains it very well --> Using different Web.config in development and production environment 这里有一个很好的答案,很好地解释了它-> 在开发和生产环境中使用不同的Web.config

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

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