1

I have an application using Entity Framework (database first) on top of a SQL Server database. The application is configured with default settings, like I've built all of my applications for the past couple of years.

However, with this particular application, when running on my windows server, I'm getting the following error now and then (quite often):

Exception message: 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).

The issue never occurs when the application is running locally through Visual Studio (connecting to the same remote SQL Server).

I know for certain that there is no error in the connection string, because as I said, the issue only happens sometimes. Other times it works just fint.

Furthermore, if I copy the entire web.config from the application running on my web server and paste it into my local development environment, it works just fine.

I thought it might be my webserver that was having issues accessing the SQL Server; but the other applications running on the same webserver, accessing the same SQL Server, are all working just fine.

I simply can't figure out what can be causing this, as Ive never experienced anything like it. What am I missing? What should I be looking for?

My connection string:

<add name="MyDbEntities" 
     connectionString="metadata=res://*/Model.MyModel.csdl|res://*/Model.MyModel.ssdl|res://*/Model.MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MyServer\MyInstance;initial catalog=MyDb;integrated security=False;User ID=MyUser;Password=MyPassword;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />
4
  • Is your database perhaps in single user mode? Commented Jan 10, 2017 at 11:46
  • Good guess, but no. It's in multi-user mode, and I have no issues connection to it from my application running locally, and through Management Studio at the same time. Commented Jan 10, 2017 at 11:47
  • This could be a name resolution/DNS issue. Do the application server and your workstation connect to the SQL Server over the same network link(s)? Does the issue go away if you connect to the SQL Server instance by IP address and port number rather than by name? Commented Jan 10, 2017 at 11:55
  • The two (Application server and SQL Server) are located on the same physical server, on 2 different virtual servers. Web server running on 192.168.0.200 and SQL server running on 192.168.0.196. My connection string is using 192.168.0.196\InstanceName. When I connect to the SQL server from my own PC, it's through a PP2P VPN tunnel. Commented Jan 10, 2017 at 12:04

1 Answer 1

1

As it turns out, the issues were caused by my Owin context. As I don't use the ApplicationUserManager part of owin (I have my own custom tables for authentication), I do not need Owin to set it up for me. However, because I had the following code in my Startup.Auth, owin would try to connect to the DefaultConnection whenever the session expired:

app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

I simply commented out the above (note: I can only do this, because my application does not use the ApplicationUser tables in the database), and it works.

Sign up to request clarification or add additional context in comments.

1 Comment

Been strugling with a similar issue, it was the connection name on the ApplicationDbContext, your answer made me look into it, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.