vidly-mvc-5 icon indicating copy to clipboard operation
vidly-mvc-5 copied to clipboard

025. Unable to run Update-database

Open GFOX91 opened this issue 5 years ago • 6 comments

Hi,

I am unable to update the database I was first told tat VS could not find any instance of a local DB so I have installed LocalDB using SQL Server Express.

I am now greeted with the following error 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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)

My Connection string in web.config is as follows:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Vidly-20190922050545.mdf;Initial Catalog=aspnet-Vidly-20190922050545;Integrated Security=true"

Can anyone help with this?

Thanks

GFOX91 avatar Sep 23 '19 09:09 GFOX91

Update I have managed to update-database by changing the source to .\SQLEXPRESS

however I am unable to connect to the data source in server explorer when clicking the .mdf file in app data i get the following:

image

GFOX91 avatar Sep 23 '19 11:09 GFOX91

hey did you get the result i'm still getting the error. my previous connection string was

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|Data Directory|\aspnet-shutter-20200323030420.mdf;Initial Catalog=aspnet-shutter-20200323030420;Integrated Security=True" providerName="System.Data.SqlClient" />

then i changed source to and now

<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet-shutter-20200323030420.mdf;Initial Catalog=aspnet-shutter-20200323030420;Integrated Security=True" providerName="System.Data.SqlClient" />

still getting same error i.e a network related.... can you help me with this

kashifnehal avatar Mar 24 '20 07:03 kashifnehal

Change connection string as below at web.config

<add name="DefaultConnection"
         connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=aspnet-Events;Integrated Security=True"
         providerName="System.Data.SqlClient" />

Then, run "Update-Database -Verbose" at package manager Thanks,

tutul2010 avatar Aug 29 '20 06:08 tutul2010

ok update-database works now but I have nothing under App_Data when clicking show all files

thelordgod avatar Jan 29 '21 07:01 thelordgod

Hi @thelordgod ,

There is no db files creation at App_Data. The Database will create at urs locally installed sql server.. Open Visual studio 2017\2019 IDE then click on 'View' at top of IDE and then click SQL Server Object Explorer as below image

Many Thanks,

tutul2010 avatar Jan 29 '21 08:01 tutul2010

I've found it, thank you very much!

thelordgod avatar Jan 29 '21 08:01 thelordgod