如何使用Visual Studio将Azure SQL备份(.bacpac)导入LocalDB?

时间:2022-04-06 05:38:16

I imagine this would be quite a mainstream scenario but I can't find how to import an exported Azure SQL database (.bacpac) into my LocalDB in Visual Studio 2013. Am I missing something or Visual Studio missing something?

我想这将是一个非常主流的场景,但我找不到如何将导出的Azure SQL数据库(.bacpac)导入Visual Studio 2013中的LocalDB。我是否遗漏了某些内容或Visual Studio缺少某些内容?

(Note: there are solutions here when one has SQL Server management studio but I don't have it and prefer not to install it, if possible.)

(注意:有一个解决方案,当有一个SQL Server管理工作室,但我没有它,如果可能的话,不想安装它。)

2 个解决方案

#1


22  

If you have this folder on your machine C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin then you can run this command to restore the bacpac file:

如果您的计算机上有此文件夹C:\ Program Files(x86)\ Microsoft SQL Server \ 110 \ DAC \ bin,则可以运行此命令来恢复bacpac文件:

.\SqlPackage.exe /Action:Import /SourceFile:"c:\temp\your.bacpac" /TargetConnectionString:"Data Source=(localdb)\v11.0;Initial Catalog=devdb; Integrated Security=true;"

If that folder's missing you will need to download the tooling from Microsoft.

如果缺少该文件夹,则需要从Microsoft下载该工具。

#2


7  

For me the right command to use was:

对我来说,正确的使用命令是:

.\SqlPackage.exe /Action:Import /SourceFile:"c:\temp\your.bacpac" /TargetConnectionString:"Data Source=(localdb)\mssqllocaldb;Initial Catalog=DBNAME;Integrated Security=true;"

。\ SqlPackage.exe / Action:Import /SourceFile:"c:\temp\your.bacpac“/ TargetConnectionString:”Data Source =(localdb)\ mssqllocaldb; Initial Catalog = DBNAME; Integrated Security = true;“

Otherwise I would get an error: *** Error importing database:Could not import package. Unable to connect to master or target server 'DBNAME'. You must have a user with the same password in master or target server 'DBNAME'.

否则我会收到错误:***导入数据库时​​出错:无法导入包。无法连接到主服务器或目标服务器'DBNAME'。您必须在主服务器或目标服务器“DBNAME”中拥有具有相同密码的用户。

Using VS2015, in the location specified by anjdreas:

使用VS2015,在anjdreas指定的位置:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130

C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ Extensions \ Microsoft \ SQLDB \ DAC \ 130

#1


22  

If you have this folder on your machine C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin then you can run this command to restore the bacpac file:

如果您的计算机上有此文件夹C:\ Program Files(x86)\ Microsoft SQL Server \ 110 \ DAC \ bin,则可以运行此命令来恢复bacpac文件:

.\SqlPackage.exe /Action:Import /SourceFile:"c:\temp\your.bacpac" /TargetConnectionString:"Data Source=(localdb)\v11.0;Initial Catalog=devdb; Integrated Security=true;"

If that folder's missing you will need to download the tooling from Microsoft.

如果缺少该文件夹,则需要从Microsoft下载该工具。

#2


7  

For me the right command to use was:

对我来说,正确的使用命令是:

.\SqlPackage.exe /Action:Import /SourceFile:"c:\temp\your.bacpac" /TargetConnectionString:"Data Source=(localdb)\mssqllocaldb;Initial Catalog=DBNAME;Integrated Security=true;"

。\ SqlPackage.exe / Action:Import /SourceFile:"c:\temp\your.bacpac“/ TargetConnectionString:”Data Source =(localdb)\ mssqllocaldb; Initial Catalog = DBNAME; Integrated Security = true;“

Otherwise I would get an error: *** Error importing database:Could not import package. Unable to connect to master or target server 'DBNAME'. You must have a user with the same password in master or target server 'DBNAME'.

否则我会收到错误:***导入数据库时​​出错:无法导入包。无法连接到主服务器或目标服务器'DBNAME'。您必须在主服务器或目标服务器“DBNAME”中拥有具有相同密码的用户。

Using VS2015, in the location specified by anjdreas:

使用VS2015,在anjdreas指定的位置:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130

C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ Extensions \ Microsoft \ SQLDB \ DAC \ 130