visual-studioentity-framework

Visual Studio C#: Update-Database issue


I got a code-first project hosted online (Website).

When I run [Update-Database] from the console on Visual Studio, it update my local database but if I change my ConnectionString to the online one, it update the Online Database (production)

How can I force Update-Database to use online connection string without changing my CnnString?

In code I'm currently using a cmd line variable (added in IIS) to distinguish if the program is running local or online in order to allow the program to branch eitheir local or online for some code.

But when I run Update-Database, it use the "current" Db ConnectionString.

I'm mostly using Update-Database local, but I need to do it for online before publishing.

I didn't find the documentation for Update-Database, is there any option to it ?

I found the [Update-Database 0] method, which is very useful so I'm thinking there might be more option to [Update-Database].

Answer by Cody Liang: using [Update-Database -Connection "here your connection string"]


Solution

  • For more information on how to use Update-Database, you can refer to the content in this document.

    Meanwhile, regarding your requirement of wanting to update both the online database as well as the local database without changing the ConnectionString, the answer is, it can't be done at design time. Basically, you need to manually run the migration script on each tenant's database. Here is a post similar to your requirement, you can refer to it.

    Answer: In the document, we see the acceptable argument for Update-Database. One of them is -Connection, therefore, using [Update-Database -Connection "here your connection string"] would fix the issue