简体   繁体   English

从本地MDF到SQL Server应用程序的迁移

[英]Local MDF to SQL Server Application Migration

I am in the process of designing a database application that will ultimately be a multi-user application. 我正在设计一个数据库应用程序,该数据库应用程序最终将是一个多用户应用程序。 However for ease of development purposes I was planning on using the built in local .MDF file for Visual Studio for now. 但是,为了便于开发,我现在计划使用Visual Studio的内置本地.MDF文件。

Once I am ready to move this into a multi-user environment is it just a matter of moving the .MDF to the server and attaching it, then changing a connection string? 一旦准备好将其移到多用户环境中,是否只需将.MDF移至服务器并附加它,然后更改连接字符串? Or is it going to be a project in of itself and I am better off just using the SQL Server from the beginning? 还是它本身就是一个项目,而从一开始就使用SQL Server更好?

Edit : it would be considerably easier for me to do development from the .MDF because I do a lot of work from home and that would mean I need to use VPN (Very slow). 编辑 :对我来说,从.MDF进行开发会容易.MDF因为我在家做很多工作,这意味着我需要使用VPN(非常慢)。

Another option I am considering is to use SQL Server Express on my local machine and then migrate that to the production server when I am ready. 我正在考虑的另一种选择是在本地计算机上使用SQL Server Express,然后在准备就绪时将其迁移到生产服务器。

As already said by Erik, you are already using SQL server. 正如Erik所说,您已经在使用SQL Server。

Just so you know, I'm using the .MDF file for development and once the changes are done, I publish them to production. 大家知道,我正在使用.MDF文件进行开发,完成更改后,我会将其发布到生产环境中。

To do this, You need to keep following points in mind. 为此,您需要牢记以下几点。

  • You shouldn't use this method to replace/copy data although it is possible. 尽管有可能,但您不应使用此方法来替换/复制数据。
  • Use this method to copy/update the schema easily. 使用此方法可以轻松地复制/更新架构。
  • The production database should be accessible from your development machine. 生产数据库应该可以从您的开发机器上访问。
  • You'll need visual studio for publishing the changes 您将需要Visual Studio来发布更改

What I follow is below (All the steps are in Visual Studio 2015 Update 3 ): 下面是我遵循的内容(所有步骤都在Visual Studio 2015 Update 3中 ):

  • Make whatever changes you need in the MDF file. 在MDF文件中进行所需的任何更改。
  • Open "SQL Server Object Explorer" in Visual studio (View->"SQL Server Object Explorer") 在Visual Studio中打开“ SQL Server对象资源管理器”(“视图”->“ SQL Server对象资源管理器”)
  • Expand the SQL server node containing your attached database. 展开包含附加数据库的SQL Server节点。
  • Right click the name of your database and choose "Schema Compare..." 右键单击数据库名称,然后选择“模式比较...”
  • In the window that opens, select the option "Select Target..." from the top bar of the window. 在打开的窗口中,从窗口的顶部栏中选择“选择目标...”选项。
  • Choose the connection to your production if already connected from the drop-down or click "Select connection..." button to connect to your production server. 从下拉列表中选择与您的产品的连接(如果已连接),或单击“选择连接...”按钮以连接到您的产品服务器。
  • Click "Compare" on the toolbar in the window. 在窗口的工具栏上单击“比较”。

All the schema differences will be listed in the area below the toolbar. 所有架构差异将在工具栏下方的区域中列出。

  • Now, you can select the changes you need to publish to production via the check-boxes. 现在,您可以通过复选框选择要发布到生产中的更改。
  • Once done, just click the "Update" button on the window toolbar and confirm the update. 完成后,只需单击窗口工具栏上的“更新”按钮并确认更新。

The selected changes from your mdf file will be copied to the production database. 从mdf文件中选择的更改将被复制到生产数据库。 In case of any error, the errors will be displayed in the results. 如有任何错误,错误将显示在结果中。

You are already using SQL Server. 您已经在使用SQL Server。 The difference here is whether or not you want to attach it to a JIT SQL Server instance or by connecting directly to a SQL Server instance. 此处的区别在于您是将其附加到JIT SQL Server实例还是直接连接到SQL Server实例。

If you plan to use a real SQL Server instance anyways in the future, it's best to just avoid the App_Data folder. 如果您打算将来使用真实的SQL Server实例,最好避免使用App_Data文件夹。

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

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