简体   繁体   English

应用程序Web部署到单独的Web服务器后的SQL Server错误

[英]SQL Server Error After Web Deploy of App to Separate Web Server

I'm getting the following error once I move the app off onto its own Windows 2012 R2 IIS web server that is on Prem. 将应用程序移至Prem上其自己的Windows 2012 R2 IIS Web服务器后,出现以下错误。 The SQL 2014 DB server is in Azure. SQL 2014数据库服务器在Azure中。 Firewall is disabled. 防火墙已禁用。

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: 26 - Error Locating Server/Instance Specified) (提供者:SQL网络接口,错误:26-指定服务器/实例时出错)

Further: 进一步:

The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. 连接字符串使用应用程序的App_Data目录中的数据库位置指定本地Sql Server Express实例。 The provider attempted to automatically create the application services database because the provider determined that the database does not exist. 提供者尝试自动创建应用程序服务数据库,因为提供者确定该数据库不存在。

My connection strings DO NOT specify any local SQL Express DB: 我的连接字符串不指定任何本地SQL Express数据库:

 <connectionStrings>
    <remove name ="NewUserToolContext"/>
    <remove name ="DefaultConnection"/>
    <add name="NewUserToolContext" connectionString="Data Source=SQLDBSERVERNAME;Initial Catalog=NewUserTool;Integrated Security=False;User Id = USERID;password = PASSWORD" providerName="System.Data.SqlClient" />
    <add name="DefaultConnection" connectionString="Data Source=SQLDBSERVERNAME;Initial Catalog=NewUserTool;Integrated Security=False;User Id = USERID;password = PASSWORD" providerName="System.Data.SqlClient" />
  </connectionStrings>

My partial _Layout view has some code that checks role membership before displaying specific menu items. 我的_Layout部分视图具有一些代码,这些代码在显示特定菜单项之前检查角色成员身份。 After doing a lot of searches on this I found old posts from 2012 and one post from way back in 2013 regarding some kind of membership initializer. 经过大量搜索之后,我发现了2012年的旧帖子和2013年的一篇关于某种成员初始化程序的帖子。 The post was incredibly vague and confusing and didn't seem relevant. 该帖子令人难以置信的模糊和混乱,似乎并不相关。 It also didn't explain anything about what to do, especially not for MVC 6 Entity Framework in 2017. I tried, I couldn't find anything they were talking about. 它也没有解释该怎么做,尤其是2017年的MVC 6 Entity Framework。我尝试过,我找不到他们在说什么。 I started learning ASP.NET last year with MVC 6. 我从去年开始使用MVC 6学习ASP.NET。

Firstly, have you enable 1433 port in the firewall of your VM? 首先,您是否在VM的防火墙中启用了1433端口? If no, you could turn on this port using following steps. 如果否,则可以使用以下步骤打开此端口。

  1. On the Start menu, click Run, type WF.msc, and then click OK. 在“开始”菜单上,单击“运行”,键入WF.msc,然后单击“确定”。
  2. In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then click New Rule in the action pane (upper right corner). 在具有高级安全性的Windows防火墙的左窗格中,右键单击“入站规则”,然后在操作窗格(右上角)中单击“新建规则”。
  3. In the Rule Type dialog box, select Port, and then click Next. 在“规则类型”对话框中,选择“端口”,然后单击“下一步”。
  4. In the Protocol and Ports dialog box, select TCP. 在“协议和端口”对话框中,选择“ TCP”。 Select Specific local ports, and then type the port number of the instance of the Database Engine, by default SQL Server uses 1433. Please input 1433 and Click Next until finish the steps. 选择“特定本地端口”,然后键入数据库引擎实例的端口号,默认情况下,SQL Server使用1433。请输入1433,然后单击“下一步”,直到完成步骤。

Secondly, you also need to enable 1433 port in Network Security Group which related to your VM. 其次,您还需要在Network Security Group中启用与您的VM相关的1433端口。 Steps below are for your reference. 以下步骤供您参考。

  1. Find the Network Security Group name which related to your VM in Netowrk interfaces panel. 在Netowrk接口面板中找到与您的VM相关的网络安全组名称。

在此处输入图片说明

  1. Open this NSG, click [Add] button in the Inbound security rules panel 打开此NSG,单击“入站安全规则”面板中的[添加]按钮。

在此处输入图片说明

  1. Add a rule as following. 添加如下规则。

在此处输入图片说明

  1. After that, you could access the database hosted in VM. 之后,您可以访问VM中托管的数据库。

Edit 2017/6/13 编辑2017/6/13

Firstly, I suggest you write the connection string to a log file before using it on your server. 首先,我建议您在服务器上使用连接字符串之前将其写入日志文件。 You will find whether the right connection string is used to connect your server. 您会发现是否使用正确的连接字符串来连接服务器。 Maybe the connection string is override by other configurations. 也许连接字符串被其他配置覆盖。

In addition, is your web server hosted on Azure VM or local machine? 此外,您的Web服务器是否托管在Azure VM或本地计算机上?

Please also try to enable 32-bit applications in your app pool advanced setting. 也请尝试在您的应用程序池高级设置中启用32位应用程序。

在此处输入图片说明

Some other things you could try. 您可以尝试其他一些方法。

  1. Please check whether you have configured Dynamic IP Security or ipSecurity in your web.config. 请检查您是否在web.config中配置了动态IP安全性或ipSecurity。 It will block any IP addresses based on your configuration. 它将根据您的配置阻止任何IP地址。

  2. Have you tried removing all the original files at your test server when deploying your release? 在部署发行版时,您是否尝试过删除测试服务器上的所有原始文件?

在此处输入图片说明

After discovering finally that it was not using the correct connection strings I provided in the web.config , but rather the LocalSqlServer connection string in the machine.config , I soon realized that it was using that because it was being referenced in the AspNetSqlMembershipProvider and AspNetSqlProfileProvider and role provider sections in the machine.config. 最终发现它使用的不是我在web.config提供的正确连接字符串,而是使用了machine.configLocalSqlServer连接字符串后,我很快意识到它正在使用它,因为它在AspNetSqlMembershipProviderAspNetSqlProfileProvider被引用和machine.config中的角色提供程序部分。 I had to find/replace everything referencing LocalSqlServer and replace it with the connection name I wanted to use, DefaultConnection . 我必须查找/替换所有引用LocalSqlServer ,并将其替换为我想使用的连接名称DefaultConnection I then had to run aspnet_regsql.exe on my developer machine from the visual studio command prompt, and point it to the database to create the schema. 然后,我必须在Visual Studio命令提示符下的开发人员计算机上运行aspnet_regsql.exe ,并将其指向数据库以创建架构。 After this my application began working. 之后,我的应用程序开始工作。

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

相关问题 Web应用程序到SQL Server的连接未连接(指定服务器/实例时出错) - Web App to SQL Server Not Connecting ( Error Locating Server/Instance Specified) 如何将 ASP.NET Web 应用程序部署到 Azure 与现有的 Z9778840A0104CB30C52ZB7 服务器数据库 (76410CB30C52ZB7) 服务器数据库 - How to deploy an ASP.NET Web App to Azure with an existing SQL Server database (Azure Data Studio) 从SQL Server Express迁移到SQL Server asp.net Web应用程序登录时出现错误 - Getting an error when moving from SQL Server Express to SQL Server asp.net web app logon 在Web应用程序中将SQL Server数据导出到Excel - Export SQL Server data to Excel in a web app 简单Web应用程序的替代SQL Server - Alternative to SQL Server for a simple web app 将SQL Server和Web App部署到Azure - Deploying SQL Server & Web App to Azure 如何在本地Web服务器上部署低信任度SharePoint应用程序 - How to deploy a low-trust SharePoint app on a local web server 如何在 azure web 应用程序上部署信号 R 自主机服务器 - How to deploy a signal R self host server on azure web app 将ASP.NET App部署到Web服务器所需的最少文件 - Minimal files needed to deploy ASP.NET App to the Web Server ASP.NET MVC Web应用程序用户登录后,SQL Server Express无法连接而没有任何有用的错误信息 - SQL Server Express fails to connect without any useful error information after ASP.NET MVC Web App user login
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM