如何将 SQL Server LocalDb 数据库从一台机器移动到另一台机器? [英] How can I move a SQL Server LocalDb database from one machine to another?

查看:39
本文介绍了如何将 SQL Server LocalDb 数据库从一台机器移动到另一台机器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 VS2012 创建的 SQL Server 数据库.我为此找到了数据库文件.我想备份数据库并将其移动到另一台机器上.

I have a SQL Server database that was created from VS2012. I located the database files for that. I would like to back up the database and move it to a different machine.

  • 我的应用程序已经启动并正在运行.在复制文件之前,我是否需要以某种方式停止数据库?我没有安装 SQL Server Management,所以如果我必须这样做,我不知道该怎么做.

  • My application already has started up and is running. Do I need to somehow stop the database before I copy the files? I don't have SQL Server Management installed so if I have to do that I am not sure how to do it.

我可以只复制数据库和日志文件并将它们移到另一台机器上吗?

Can I just make a copy of the database and the log file and move them to another machine?

数据库文件在我的 C:\Users\Melina 文件夹中.另一台机器上的 VS2012 可以在我不做任何事情的情况下访问数据文件吗?我有以下连接字符串:

The database files are in my C:\Users\Melina folder. Will the VS2012 on the other machine be able to access the data files without me doing anything?I have the following connectionString:

 <add 
  name="TestContext" 
  connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Test;Integrated Security=SSPI;" 
  providerName="System.Data.SqlClient" />

推荐答案

  1. 从原始机器备份您的数据库1) 打开 SQL Server Management Studio,连接到您的 (LocalDb),选择您的数据库,然后右键单击,选择任务 -> 备份...2) 记住备份数据库对话框中的目标路径,然后单击确定

  1. Backup your database from original machine 1) Open SQL Server Management Studio, connect to your (LocalDb), select your database then right-mouse-click, choose Tasks -> Back Up ... 2) Remember the Destination path in Back Up Database dialog, then click OK

将创建的 .bak 复制到目标机器

Copy the created .bak to your target machine

如果之前未安装 SQL Server,请在目标计算机上安装它

Install SQL Server on your target machine if it's not installed previously

做相反的操作在你的目标机器上恢复1)打开SQL Server Management Studio,在对象资源管理器中,选择Databases,然后鼠标右键,选择Restore Database,打开Restore Database对话框2) 给数据库命名3) 在 Source for restore 下,选择 From device,然后浏览到您复制的 .bak 文件,然后单击 OK

Do the opposite operation Restore on your target machine 1) Open SQL Server Management Studio, in Object Explorer, select Databases, then right-mouse-click, select Restore Database, open Restore Database dialog 2) Give a name to To Database 3) Under Source for restore, choose From device, then browse to your copied .bak file, then click OK

这篇关于如何将 SQL Server LocalDb 数据库从一台机器移动到另一台机器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆