How to use Entity Framework and code-first in WebApi to create a database entity-framework-6


Newbie here.


When I open the SQL Server Object explorer from the menu in VS2017, I did not find my database called UserRegistryDB.

Please help. I did the following.

  1. I have installed SQL Server 2017 EXPRESS

  2. I add Entity Framework to reference in the project.

  3. I have created a class UserDBContext.cs in the Model folder

    public class UserDBContext : DbContext
        public DbSet<User> Users { get; set; }
  4. I have added a model class in Model folder

    public class User
            public int Id { get; set; }
            public string emailID { get; set; }
            public string AppName { get; set; }
            public string SessionToken { get; set; }
  5. I have added this in the web.config:

        <add name="UserDBContext"
             connectionString="server=.; database= UserRegistryDB; integrated security = true;"
             providerName ="System.Data.SqlClient"/>
  6. I build my project and run it; there are no compilation error, build success.

I need help with the question:

what are the differences in connection string that using server =. , server=(local) ? or server=(localdb)

connectionString="server=. ; database= UserRegistryDB; integrated security = true;"

connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=TestDatabase;Integrated Security=True"


10/10/2017 10:15:25 AM

Popular Answer

. and (local) refer to the installed default instance - the instance without any specific instance name (will be shown in SQL Server Configuration Manager as MSSQLSERVER). This can be any edition of SQL Server - Express, Web, Standard, Enterprise, Developer etc.

(localdb) refers to an installed SQL Server Express LocalDB instance - that's a developer-oriented version of SQL Server Express that isn't installed as a Windows Service and runs all the time, but instead only starts up and runs while your Visual Studio or your application is running

10/10/2017 10:17:39 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow