2

In Visual Studio 2013, I created an ASP .NET MVC web project with ASP.Net Identity.

And the Entity Framework Code First created a SQL Server Express LocalDB db in

APP_Data folder by default.

But I prefer a SQL Server Express db because SQL Server Express LocalDB couldn't work with IIS when I hosted the web app in local IIS.

So my questions are,

  1. How can I create a SQL Server Express db rather than a SQL Server Express LocalDB db by default when I create a new project with EF Code First?

    I have installed SQL Server Express even I have replaced "(LocalDB)\v11.0" with ".\SQLEXPRESS " in "Tools - Options - Data tools - Data connection - Instance name" of VS2013. But they didn't work for me.

  2. Let us say now we have to use SQL Server Express LocalDB for ASP.Net Identity and my db, I wonder whether there will be an easy way to convert my LocalDB db to SQL Server Express or SQL Server db when I finish development and deploy my app to IIS.

Thank you in advance.

1
  • 1
    where is the problem just change in your web.config the connection string from LocalDb to .\SqlExpress?! connection string in is located in your APP_Data Commented Jul 4, 2016 at 9:49

2 Answers 2

2

Specify the connection string name in your code first DbContext class like this:

public class MyDbContext : DbContext
{
    public MyDbContext(): base("name=connectionString")
    {
    }

    public DbSet<User> Users { get; set; }
    public DbSet<Order> Orders { get; set; }
}

Then inside the Web.config file specify the connection string to point to which ever version of SQL server that you desire:

  <connectionStrings>
    <add name="connectionString" connectionString="Password=password;Persist Security Info=True;User ID=sa;Initial Catalog=DatabaseName;Data Source=ServerName"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
Sign up to request clarification or add additional context in comments.

Comments

0

After so many times trying, I found the answers myself and would like to share here.

  1. Just modify "(LocalDB)\v11.0" to ".\SQLEXPRESS" for value of DefaultConnection in web.config and grant enough permissions for the context login id in advance of generating of DB(in case of update-database command in NuGet PkgMgr Console, or running your web app in vs).

  2. You may attach LocalDB file to SQL Server Express instance.

Hope to be helpful for someone.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.