使用LocalDB发布ASP.net网站

时间:2022-04-20 07:23:21

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. 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. 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. Once I get home I then publish to my Server.

我正在尝试在我家网络上的另一台计算机上发布我的网站。我在该计算机上设置了IIS和SQL Server 2016 Express。我的开发笔记本电脑上版本相同当我运行该网站时,我得到以下错误。我认为问题可能是我正在尝试使用LocalDB。我经常旅行,在我没有互联网连接的地方。这就是为什么我认为在开发时最好使用localDB。一旦我回到家,我就会发布到我的服务器。

Originally the LocalDB was created on my computer in a folder that was far from my project. So what I did was move it to the app_data so that it would be attached when I publish.

最初,LocalDB是在我的计算机上创建的,远离我的项目。所以我做的是将它移动到app_data,以便在我发布时附加它。

What I tried:

我尝试了什么:

  1. Reinstalled Microsoft SQL Server 2016 (made sure LocalDB was installed)
  2. 重新安装Microsoft SQL Server 2016(确保已安装LocalDB)

  3. Ensured the database was in fact in App_Data folder on server
  4. 确保数据库实际上位于服务器上的App_Data文件夹中

  5. Changed connection string to look for database in app_data
  6. 更改了连接字符串以在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. 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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist. )

建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供程序:SQL网络接口,错误:50 - 发生本地数据库运行时错误。指定的LocalDB实例不存在。)

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.

描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.)

异常详细信息:System.Data.SqlClient.SqlException:建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供程序:SQL网络接口,错误:50 - 发生本地数据库运行时错误。指定的LocalDB实例不存在。)

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.`

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息

1 个解决方案

#1


0  

As Steve mentioned in the comments, I have confirmed that using localDB in production is frowned upon.

正如Steve在评论中提到的那样,我已经确认在生产中使用localDB是不受欢迎的。

Solution: Use a SQL Server on my development machine and a separate one on my production server. All I have to do is have separate connection strings in my Web.Config.

解决方案:在我的开发计算机上使用SQL Server,在生产服务器上使用单独的SQL Server。我所要做的就是在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.Release.Config

There is a great answer here that explains it very well -->Using different Web.config in development and production environment

这里有一个很好的答案可以很好地解释它 - >在开发和生产环境中使用不同的Web.config

#1


0  

As Steve mentioned in the comments, I have confirmed that using localDB in production is frowned upon.

正如Steve在评论中提到的那样,我已经确认在生产中使用localDB是不受欢迎的。

Solution: Use a SQL Server on my development machine and a separate one on my production server. All I have to do is have separate connection strings in my Web.Config.

解决方案:在我的开发计算机上使用SQL Server,在生产服务器上使用单独的SQL Server。我所要做的就是在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.Release.Config

There is a great answer here that explains it very well -->Using different Web.config in development and production environment

这里有一个很好的答案可以很好地解释它 - >在开发和生产环境中使用不同的Web.config