Tag Archives: Deploy Web Package

Creating a Database Upon Deploy of Microsoft Web Site

Our development work includes a website we are creating for a client for whose system we don’t have direct access. We need a way to create a Web Deploy Package that we can turn over to them and ask them to deploy on their system.

Creating the Web Deploy Package was easy – just follow the directions that can be found in a number of places to use the GUI within Visual Studio 2012 and create it. The hard part was getting the database to create itself.

Theoretically, according to what I was reading, I should have to do is click the box that says, Execute Code First Migrations (runs on application start). Nope. Didn’t work. The database wasn’t created when I deployed. And, when I ran the application, nothing happened; no database was created.

I did try creating the database before running the app, then expecting the tables to be created. but they weren’t.

After much struggling, and a whole lot of research, I finally got it working. The following are the steps that I needed to have in place for this to occur:

  1. Within your Configuration.cs (if using C#) file (created automatically when you create a migration), set:
    • AutomaticMigrationsEnabled = true
  2. Create a duplicate of your connection string in your web.config file.
    • In the deployment settings, on the first string (your original string), check the box that says Execute Code First Migrations (runs on application start)
    • On the second string, check the box that says, Update database
  3. Create a database user for your database. Windows Authentication didn’t work. Neither did ‘sa’, although that was supposed.
  4. Upload some data. Click the Configure database updates link on the Settings. You’ll be given the option to add SQL files to run after the database is created. Attach one with some minimal data for your database.

And that worked! I created the database on the other server. I created the user, with SA access on the new database. I ran my deployment script, as per the instructions provided and voila! the new tables were created and populated!