33

I'm trying to launch .Net Core 2.0 application on Ubuntu 17.04. I developed it on Windows 10 before and it works well. The problem is that when I run dotnet ef database update I get the next exception:

System.PlatformNotSupportedException: LocalDB is not supported on this Platform.

Here is my DbContext:

public class NutritionContext : DbContext
{
    public DbSet<User> Users { get; set; }
    public DbSet<Meal> Meals { get; set; }
    public DbSet<Dish> Dishes { get; set; }
    public DbSet<Product> Products { get; set; }
    public DbSet<Plan> Plans { get; set; }
    public DbSet<MealDish> MealDishes { get; set; }
    public DbSet<Ingredient> Ingredients { get; set; }
    public DbSet<PlanDetail> PlanDetails { get; set; }
    public DbSet<UserPlan> UserPlans { get; set; }
    public DbSet<AuthUser> AuthUsers { get; set; }

    public NutritionContext()
    {
    }

    public NutritionContext(DbContextOptions options) : base(options)
    {           
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(
            "Server=(localdb)\\mssqllocaldb;Database=NutritionDatabaseNew;Trusted_Connection=True;MultipleActiveResultSets=true");
    }

}

Do you know what could be the reason of it?

5
  • 11
    The reason: "LocalDB is not supported on this Platform."
    – Gusman
    Aug 24, 2017 at 11:52
  • It's not possible. Who told you are able to use localDB on Ubuntu?
    – Sinatr
    Aug 24, 2017 at 11:57
  • 2
    The work around, do not use LocalDB on that platform. Use a different database provider instead. There is nothing else that can be said or done about it (short of you joining the Microsoft db development team and add functionality to make LocalDB compatible with this platform)
    – Igor
    Aug 24, 2017 at 11:58
  • 1
    ok thanks, I didn't know I can't use LocalDB on ubuntu
    – YTerle
    Aug 24, 2017 at 12:05
  • 26
    I'm sorry? How is this off-topic? Sure, it's a descriptive error but on a multi-platform tool such as dotnet how is that error supposed to be intuitive? How are we supposed to just know there's not a missing dependency? Nov 20, 2018 at 21:14

4 Answers 4

37

LocalDb is a packaging mechanism for SQL Server Express Edition, and is only available for Windows. On Ubuntu you can install regular SQL Server Express Edition.

https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-overview

Here are the install scripts for Ubuntu, Red Hat, and SUSE.

Or use the Docker Images:

https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker

2
  • sorry @david-browne-microsoft, Did u meant to say "On Ubuntu you can install regular SQL Server E̶x̶p̶r̶e̶s̶s Edition." ?
    – Ruslan
    Jul 22, 2020 at 12:10
  • LocalDb is a flavor of Express Edition, but you can install any edition with the Linux installer or docker image. Jul 22, 2020 at 13:22
6

I had this problem when switching from a windows machine to MacBook Pro. As others pointed out, LocalDB is for SQL Server Express Edition (available for windows).

To fix this, you'll need to install SQL Server and use localhost instead of LocalDB.

0

For Linux systems based on Arch the mssql-server package seems to be the way to go.

0

I had a problem with running Asp.Net Core 6 web application on Ubuntu V 20.04 (with sqlserver installed locally on ubuntu). enter image description here

I have a connection string set enter image description here

To Fix this: I had to change my connection string to explicitly specify userid and password set Encrypt=false. Also instead of (localdB) I have to use localhost in my connection string See more information here

"Server=localhost;Database=BethanysPieShop8854;User Id=sa;Password=passw0rd!;MultipleActiveResultSets=true;Encrypt=false"

4
  • That's not the same issue. It's about localDb here, that's not the same as "sqlserver 2022 installed locally on ubuntu". Mar 1 at 17:22
  • Sorry I forgot to mention I have to change (localdb) to localhost also in my connection string
    – Hemendr
    Mar 1 at 17:32
  • Look, you're just running SQL server, not localDb. Whatever you put in the connection string wrongly, it has nothing to do with the question. Mar 2 at 10:53
  • Don't know but I exactly face the same issue when I successfully ran my asp.net core application using SQL server on windows and then I ran the same source code on Linux Ubuntu with sqlserver installed and I received the same message "Local DB is not supported on this Platform". I fixed the issue by changing my connection string only and shared my answer the way I solved.
    – Hemendr
    Mar 2 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.