1

I am creating an on-line shop project using .NET Core 3.0 and Entity Framework Core. I have set up the applicationContextDb and the connection string in appSettings.json.

The application works just fine adding products, and these products show up in my localdb in VS2019. I need it to connect to my localhost SQL Server instance in SSMS as it will be easier in the future to manage the online shop and see the data, but I don't know how to do that and I cannot find much information about this out there. Does anyone have an idea on how to do this?

I have tried to change the name from localdb to localhost, and obviously changing it too in the connection string, but it throws an error saying that it cannot find the network path.

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tofetopo
  • 456
  • 2
  • 7
  • 20
  • 1
    In SSMS, simply specify `(localdb)\MSSQLLocalDb` as the server name to connect to the same localdb instance. – Dan Guzman May 24 '20 at 16:18

1 Answers1

1

To connect to a local default SQL Server instance (which I agree is easier in the long run than localDB), use a connection string like:

"Server=localhost;database=YourDatabaseName;Integrated Security=true"

A named instance like

"Server=localhost\SqlExpress;database=YourDatabaseName;Integrated Security=true"

Of course you have to install the SQL Server instance before this will work. You can install using the Developer Edition or Express Edition available for free download here.

After pointing to the new instance, you'll need to run your Migrations, or run myDbContext.Database.EnsureCreated() to generate the DDL for your EF model. Or copy the .mdf/.ldf into your SQL Server's data directory and Attach the database in SSMS.

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
  • Thanks for your answer, I have already downloaded SQL Server 2019 dev edition and I have a localhost instance running. If I change the connection string and I try to add a Product, it throws the following error: SqlException: Invalid object name 'Products' which leads me to think there's something more that needs tweaking than just the connection string. Does this mean that I have to create the table Products in SSMS to match VS? I though the tables and DB would be autogenerated in SSMS side. – Tofetopo May 24 '20 at 16:11
  • 1
    You just saved my day! It worked! but I had to add some extra code to the StartUp.cs class. I will add to this comment the missing bit to where to include the myDbContext.Database.EnsureCreated() part for those experiencing my same issue: https://stackoverflow.com/questions/36958318/where-should-i-put-database-ensurecreated Thanks again!! – Tofetopo May 24 '20 at 16:40