Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I point to my full SQL Server Express database in ASP.NET Core project?

Context

I have an existing project which is a data access layer that connects to a local SQL Server Express 12 database.

I now want to create a new ASP.NET Core project in the same solution which utilises this database. I also want to use the baked in user authentication with the relevant tables being added to this database.

What I've done

I've created the ASP.NET Core project successfully but it points to a newly created (localdb)MSSQLLocalDB rather than my SQL Server Express database. I changed the connection string in appsettings.json to:

"DefaultConnection": {
  "ConnectionString": "Server=MAIN-DESKTOP\\SQLEXPRESS;Database=ArbitrageSearch;Trusted_Connection=True;MultipleActiveResultSets=true"
}

I expected it to then complain about missing tables but actually the application continues to access (localdb)MSSQLLocalDB.

Question

How do I point to my existing SQL Express database and then how do I initialise the tables necessary to support user authentication?

like image 901
ifinlay Avatar asked Dec 08 '16 15:12

ifinlay


2 Answers

If the Core Application and SQL Express database are on the same server, you'll want to change the Connection String to: .\SQLExpress. This will automatically target the localhost.

Which will indicate the Express SQL Instance.

like image 96
Greg Avatar answered Oct 11 '22 17:10

Greg


  "ConnectionStrings": {
    "DefaultConnection": "Server=.\\SQLExpress;Database=netCore.Project;Trusted_Connection=True;MultipleActiveResultSets=true"  
},

Note that // is required. After that update-database PM console

like image 29
StP Avatar answered Oct 11 '22 15:10

StP