简体   繁体   English

将带有SQL Server 2008数据库的MVC3应用程序发布到IIS 7

[英]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. 我已经使用SQL Server 2008数据库在c#中开发了一个非常简单的mvc3应用程序。 I need to publish it to another PC running iis7. 我需要将其发布到另一台运行iis7的PC上。 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 提前致谢

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. 意味着您需要将数据库结构和数据库的当前内容部署到另一台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 ) 从Sql Server Management Studio内部使用复制数据库任务( http://msdn.microsoft.com/zh-cn/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 ) 如果您拥有Visual Studio 2010 Premium或Ultimate,则“数据”菜单下有一些任务用于比较和同步数据库( http://msdn.microsoft.com/zh-cn/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) 如果您拥有Visual Studio 2k8数据库,则具有类似的功能,但我从未使用过它(http:// msdn.microsoft.com/zh-cn/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) 使用sqlcmd.exe创建数据库转储,移动它们,然后使用sqlcmd将它们还原到新环境([http://msdn.microsoft.com/zh-cn/library/ms180944(v=sql.100) .aspx] [4],请查看有关维护的部分,您只需要进行备份,然后制作一个类似的.sql即可使用RESTORE命令。http://msdn.microsoft.com/zh-cn/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) (http://msdn.microsoft.com/zh-cn/library/84b1se47.aspx)

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 快速简单:将应用程序文件复制到新服务器的Web目录中,然后备份数据库,然后将其还原到新服务器上

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. 长期:您可以研究msdeploy来推动更改,并查看FluidMigrations或MS数据项目来进行数据库更改。

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). 右键单击Visual Studio解决方案资源管理器中的项目名称,然后选择“发布”,选择“ File System作为发布方法,然后指定目标位置(站点根目录或您可以找到的位置,以便稍后移动文件)。
  2. open sql server management studio, find your db, right click it, tasks, backup. 打开SQL Server Management Studio,找到您的数据库,右键单击它,执行任务,备份。 Set a destination (somewhere easy to find) and click ok (inspired by @BobTheJanitor and @theunderscoregreg). 设置一个目的地(在一个容易找到的地方),然后单击“确定”(受@BobTheJanitor和@theunderscoregreg的启发)。
  3. set up a new web site in iis on what ever machine is to host the site. 在iis上使用托管该站点的任何计算机建立一个新的站点。
  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). 在新站点根目录中,我添加了一个名为app文件夹,其中放置了第1步产生的所有文件(我是通过ftp完成的,但我想您将它们放在那里并不重要)。
  5. in iis's connections sidebar find your new site, and right click the app folder and choose convert to application. 在iis的连接边栏中,找到您的新站点,然后右键单击app文件夹,然后选择转换为应用程序。
  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. 再次在连接侧栏中,单击“ Application Pools然后选择新应用程序分配给的那个,右键单击它并选择高级设置。 set the .NET version to 4.0 and under process model set identity to LocalSystem (found this bit here ) 将.NET版本设置为4.0,并在过程模型下将标识设置为LocalSystem (在此处找到此位)
  7. in SSMS on the new host machine, right click databases and choose Restore Database... . 在新主机上的SSMS中,右键单击数据库,然后选择Restore Database... As the To database: field enter the same name you had for the db on the first machine. 在“ To database:字段中,输入与第一台计算机上的To database:相同的名称。 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. 从设备中选择,然后选择您在步骤2中制作的备份文件(我必须将文件类型更改为所有文件才能查看该文件),然后单击“确定”。
  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. 我使用ADO.NET Entity Data Model项目项来创建.edmx模型,该模型将一个连接字符串添加到Web.Config文件中,该文件名为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. 此连接字符串似乎特定于PC,因为字符串的Source=部分引用了特定的计算机,因此我必须对其进行编辑。 in iis again, choose your site and then the app folder. 再次在iis中,选择您的站点,然后选择app文件夹。 open the connection strings item in the ASP.NET section. 打开ASP.NET部分中的connection strings项。 find the somethingEntities connection string and double click it, you should now have a dialog window that will let you edit it. 找到somethingEntities连接字符串并双击它,您现在应该有一个对话框窗口,可以对其进行编辑。 all i had to do was change the pc name in the string to the name of the new host machine. 我要做的就是将字符串中的pc名称更改为新主机的名称。

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. 如果有人可以提出改进建议,或者有更好的策略,我要么更新此答案,要么接受更好的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM