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.
Secondly, you also need to enable 1433 port in Network Security Group which related to your VM. Steps below are for your reference.
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.
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.
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.