ASP.NET MVC 4, Migrations - How to run 'update-database' on a production server

前端 未结 7 750
Happy的楠姐
Happy的楠姐 2021-01-31 04:02

I can use package manager to run \'update-database -verbose\' locally.

Probably a stupid question but I can\'t find it online - once my website is deployed - how can I r

7条回答
  •  礼貌的吻别
    2021-01-31 04:05

    A simple solution: running Update-Database from your local Package Manager Console providing a connection string parameter with the production connection string. You also have to provide the connection provider name (SqlServer in this example code):

    Update-Database -ConnectionString  -ConnectionProviderName System.Data.SqlClient
    

    Instead of the connection string you can use a connection string name present in your app.config file connectionStrings section:

    Update-Database -ConnectionStringName 
    

    You must have permissions to access that server from your local machine. For example, if you are able to connect to the server from a Sql Server Management Studio you can use this.

    Note that this approach is not recommended for a real production system, you should use something like what is explained in the accepted answer. But it can help you with quick hacks in development remote servers, test environments, etc.

提交回复
热议问题