Ben
Ben

Reputation: 5715

Publishing a MVC3 application with SQL Server 2008 Database to IIS 7

Forgive me if this is a stupid question, I know there have been similar questions before, but I cannot make any thing work for me.

I have developed a really simple mvc3 application in c# using a SQL Server 2008 database. I need to publish it to another PC running iis7. I need the database structure and contents to go with the application too.

Could anyone give me a step by step walkthrough of what to do?

Thanks in advance

Upvotes: 0

Views: 656

Answers (3)

Ben
Ben

Reputation: 5715

Ok I have got it working now using the following steps:

  1. right click the project name in visual studio's solution explorer, and select publish, choose File System as the publish method and specify a target location (either the sites root directory or somewhere you can find it so you move the files later).
  2. open sql server management studio, find your db, right click it, tasks, backup. Set a destination (somewhere easy to find) and click ok (inspired by @BobTheJanitor and @theunderscoregreg).
  3. set up a new web site in iis on what ever machine is to host the site.
  4. within the new sites root, I added a single folder called app into which i placed all the files resulting from step 1 (i did it via ftp, but i guess it doesn't matter how you get them there).
  5. in iis's connections sidebar find your new site, and right click the app folder and choose convert to application.
  6. again in the connections sidebar click Application Pools and select whichever one your new app was assigned to, right click it and choose advanced settings. set the .NET version to 4.0 and under process model set identity to LocalSystem (found this bit here)
  7. in SSMS on the new host machine, right click databases and choose Restore Database.... As the To database: field enter the same name you had for the db on the first machine. choose from devices and select the backup file you made in step 2 (i had to change file types to all files to see the file) and click ok.
  8. This may be specific to my situation, not sure. I used the ADO.NET Entity Data Model project item to create the .edmx model, which adds a connection string to the Web.Config file called somethingEntities. This connectionstring appears to be specific to the pc as the Source= part of the string refers to the specific machine, so i had to edit this. in iis again, choose your site and then the app folder. open the connection strings item in the ASP.NET section. find the somethingEntities connection string and double click it, you should now have a dialog window that will let you edit it. all i had to do was change the pc name in the string to the name of the new host machine.

My new site was then working! I am far from an expert and realise that what i have done here is probably not best practise, but it works. If any one can suggest improvements, or a better strategy altogether i will either update this answer or just accept the better answer.

Upvotes: 1

Bob The Janitor
Bob The Janitor

Reputation: 20802

There is a quick and simple way of doing this if its a one time thing, and there is a long term programmable way.

Quick and simple: Copy your application files to your new server into the web directory, then back up your DB and then restore it on your new server

Long term: You can look into something msdeploy for pushing you changes and look at something like FluidMigrations or MS data project for doing your DB changes.

Upvotes: 1

theunderscoregreg
theunderscoregreg

Reputation: 11

Correct me if I'm wrong but I'm going to assume that

I need the database structure and contents to go with the application too.

Means you need the database structure and current contents of the database to be deployed to the other pc.

Depending on the tools at your disposal here are a few options:

  1. Use the Copy Database task from inside Sql Server Management Studio (http://msdn.microsoft.com/en-us/library/ms188664(v=sql.100).aspx)

  2. If you have Visual Studio 2010 Premium or Ultimate, there are tasks under the "Data" menu for comparing and synchronizing databases (http://msdn.microsoft.com/en-us/library/aa833435.aspx#synchronize)

  3. If you have Visual Studio 2k8 Database there's similar functionality but I've never used it (http:// msdn.microsoft.com/en-us/library/aa833435(v=vs.90).aspx)

  4. Use sqlcmd.exe to create dumps of your database, move those and then use sqlcmd to restore them to the new environment ([http:// msdn.microsoft.com/en-us/library/ms180944(v=sql.100).aspx][4], check out the section on maintenance. You just need to make a backup, then make a similar .sql to use the RESTORE command. http:// msdn.microsoft.com/en-us/library/ms186858(v=sql.100).aspx)

If you're going to be doing this a lot, to multiple machines, and most of your content is static, see if creating a Database Project would help you out. (http:// msdn.microsoft.com/en-us/library/84b1se47.aspx)

Upvotes: 1

Related Questions