I lost a few minutes trying to add a local database (.mdf) to a Visual Studio project recently since the error message is so cryptic.  When adding a SQL Server Database to an existing project, you may see 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: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)

Like me, you may be thinking this is strange since a local .mdf file shouldn't have anything to do with a network connection.  This is apparently a reference to the SQL Server service instance on your machine.  Unfortunately, I have a lot to run on my development machines, so I turn off the SQL Service service when I'm not actively using it.  This service must be running in order to add an .mdf file to your project.

Once I restarted the service, I could add the file no problem.

 

Add comment


Security code
Refresh

Code Project RSS
Contact Me
Contact me here: by email or check out my resume http://stuartmorris.emurse.com
Web Hosting By ICDSoft.com