0

I have an ASP MVC 5 application using Code First EF. I am setting up an environment to debug on a remote machine and follow these steps.

The website itself publishes fine, but I'm needing to publish the EF local databases along with it as well, content included. I've been digging around online but have had difficulty finding a step-by-step process for doing this that also allows for EF code first updates to the remote database.

Any help would be appreciated.

  • LocalDb isn't meant for a server publish; it's a *lightweight* database targeted for *program development*. It runs in User Mode, which makes it impractical for publishing to a server environment. It also will likely not handle multiple user connections very efficiently, making it a *huge* bottleneck for a website. – Claies Sep 27 '17 at 22:02
  • I probably didn't word my questions well enough. I'm needing to know how to migrate the information from LocalDB to SQL Express on the remote computer and make sure all my 1) connections in my code refer to that DB instead of the local (without rewriting all my code) 2) Information in the LocalDB is on the SQL Express (without having to manually build tables, fill them out, etc). – rStackSharper Sep 27 '17 at 23:26

2 Answers2

0

As for connection , try modifying the connection string in webConfig. As for the information, I'm not 100% sure on this, but I'd you think you would be able to backup the database and restore on the remote machine.

There is a _migrationHistory table in the database that EF refers to when checking the models against the database, so by restoring the whole database (and the _table as the result ) EF should not lose its state ( you won't need to run Update-Database).

farzaaaan
  • 410
  • 3
  • 9
0

If you publish to a server, you can use different appsettings for development and production using different web.config-files as described here

And for your database:

I pretend you want some content of your database being transferred into the production database in addition to get the right structure of tables too.

In this case, Migrations could do the job: If you create your database with CodeFirstMigrations you can be sure, that your structure is right, by migrating the database before publishing.

And for the data, you can use a Database-Initializer to get the required data into any database your targeting as long you have enough permission for this.

Nikolaus
  • 1,859
  • 1
  • 10
  • 16