简体   繁体   中英

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. The SQL 2014 DB server is in Azure. Firewall is disabled.

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: 26 - Error Locating Server/Instance Specified)

Further:

The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. 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:

 <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. 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. 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. I started learning ASP.NET last year with MVC 6.

Firstly, have you enable 1433 port in the firewall of your VM? 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.
  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).
  3. In the Rule Type dialog box, select Port, and then click Next.
  4. In the Protocol and Ports dialog box, select 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.

Secondly, you also need to enable 1433 port in Network Security Group which related to your VM. Steps below are for your reference.

  1. Find the Network Security Group name which related to your VM in Netowrk interfaces panel.

在此处输入图片说明

  1. Open this NSG, click [Add] button in the Inbound security rules panel

在此处输入图片说明

  1. Add a rule as following.

在此处输入图片说明

  1. After that, you could access the database hosted in VM.

Edit 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?

Please also try to enable 32-bit applications in your app pool advanced setting.

在此处输入图片说明

Some other things you could try.

  1. Please check whether you have configured Dynamic IP Security or ipSecurity in your web.config. It will block any IP addresses based on your configuration.

  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. I had to find/replace everything referencing LocalSqlServer and replace it with the connection name I wanted to use, 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. After this my application began working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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