So recently I installed Visual Studio 2017 on a laptop and I installed it with only the ASP.NET and WinForms features. I was working on a webapp and initializing the database when I realized that VS was completely unable to connect to the database. I opened the “SQL Server Object Explorer” and tried to manually connect to the MSSQLLocalDB instance and I got this 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. Error occurred during LocalDB instance startup: SQL Server process failed to start.) (Microsoft SQL Server)

I tried to start the service from the CMD and I kept on getting similar errors. Eventually, I concluded that the installation was corrupted and therefore tried reinstalling LocalDB. Guess what? It got me past this error but introduced me to another. It was something like this.

CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file ‘c:\Users\AnasDatabaseName-asdf5sdfasd5fs5dfs5f.mdf’.

This time, the CREATE Database command was failing because it was trying to create and MDF file in my “Users” folder. I checked the default location for the databases and it was in a sub-sub-sub-sub-folder inside AppData. A bit of Googling told me that this was actually a bug in the program itself and had been fixed in a recent update. So I just downloaded the latest Cumulative Update from the Microsoft site and it did the trick.