Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance

I am trying to build an ASP.NET MVC 5 Web Application which has a MyDatabase.mdf file in the App_Data folder. I have SQL Server 2014 Express installed with a LocalDb instance. I can edit the database tables using the Server Explorer, however when I debug the application and go to a page where the database is needed I get the following error.

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. Cannot create an automatic instance. See the Windows Application event log for error details.

So I looked in the Event Viewer under Application and only see one Warning over and over again.

The directory specified for caching compressed content C:\Users\User1\AppData\Local\Temp\iisexpress\IIS Temporary Compressed Files\Clr4IntegratedAppPool is invalid. Static compression is being disabled.

So I tried rebooting the server, still no go. Same error 50 as before.

I have created an class under Models where I have a class called Post.

namespace MyApplication.Models {     public class Post     {         public int Id { get; set; }         public string Title { get; set; }         public string Content { get; set; }     }      public class MyDatabase : DbContext     {         public DbSet<Post> Posts { get; set; }     } } 

I also have a Controller setup to list the posts from MyDatabase.

namespace MyApplication.Controllers {     public class PostsController : Controller     {         private MyDatabase db = new MyDatabase();          // GET: Posts         public ActionResult Index()         {             return View(db.Posts.ToList());         }     } 

In my web.config file the connection string looks like this...

<connectionStrings>     <add name="DefaultConnection"           connectionString="Data Source=(LocalDB)\v12.0;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True"           providerName="System.Data.SqlClient" /> </connectionStrings> 

I've tried the suggestion posted here but it didn't work. Also tried this.

I also notice that the MyDatabase instance gets disconnected after I start running the application. If I refresh the database using Server Explorer in Visual Studio I can view the tables.

How is it that I can connect to the database and edit it within Visual Studio 2013 but when I debug the application it cannot connect to the database?

like image 283
Jonathan Kittell Avatar asked Oct 08 '14 02:10

Jonathan Kittell


People also ask

How to resolve SQL Server Error 50 - local database runtime occurred?

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.

What does error 50 mean in SQL Server?

c# - SQL Network Interfaces Error 50 - Local Database Runtime error occurred. Cannot create an automatic instance - Stack Overflow SQL Network Interfaces Error 50 - Local Database Runtime error occurred. Cannot create an automatic instance Bookmark this question. Show activity on this post.

Why did start of localdb instance fail?

Start of LocalDB instance "MSSQLLocalDB" failed because of the following error: Cannot create an automatic instance. See the Windows Application event log for error details. ....\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB

How many instances of localdb can be installed on a server?

There can be only one installation of the LocalDB binary files for each major SQL Server Database Engine version. Multiple Database Engine processes can be started and will all use the same binaries. An instance of the SQL Server Database Engine started as the LocalDB has the same limitations as SQL Server Express


1 Answers

Breaking Changes to LocalDB: Applies to SQL 2014; take a look over this article and try to use (localdb)\mssqllocaldb as server name to connect to the LocalDB automatic instance, for example:

<connectionStrings>   <add name="ProductsContext" connectionString="Data Source=(localdb)\mssqllocaldb;    ... 

The article also mentions the use of 2012 SSMS to connect to the 2014 LocalDB. Which leads me to believe that you might have multiple versions of SQL installed - which leads me to point out this SO answer that suggests changing the default name of your LocalDB "instance" to avoid other version mismatch issues that might arise going forward; mentioned not as source of issue, but to raise awareness of potential clashes that multiple SQL version installed on a single dev machine might lead to ... and something to get in the habit of in order to avoid some.

Another thing worth mentioning - if you've gotten your instance in an unusable state due to tinkering with it to try and fix this problem, then it might be worth starting over - uninstall, reinstall - then try using the mssqllocaldb value instead of v12.0 and see if that corrects your issue.

like image 182
Bret Avatar answered Oct 12 '22 01:10

Bret