Home > SQL Azure > DacImportExportCli : Import / Export Data from SQL Azure to SQL Server (vice versa)

DacImportExportCli : Import / Export Data from SQL Azure to SQL Server (vice versa)


SQL Azure Database Import / Export v 2.0 is a command line interface to create DacPac for importing / exporting data from SQL Azure to SQL Server and vice versa.

Its available for download from https://www.sqlazurelabs.com/DacImportExportCli.zip (Note: You need to register for SQL Azure Labs for downloading beta programs)

This tool is built upon SQL Server “Denali”

It supports the following versions of SQL Servers

1. SQL Azure

2. SQL Server “Denali”

3. SQL Server 2008 SP1 or above / 2008 R2

4. SQL Server 2005 SP4 and above

5. SQL Server 2000 (Only Export is supported, Import is not supported)

To install and run this, you need the following list of components

1. .Net Framework 4.0

2. SQLSysClrTypes.msi – https://www.sqlazurelabs.com/SQLSysClrTypes.msi

3. SharedManagementObjects.msi – https://www.sqlazurelabs.com/SharedManagementObjects.msi

4. DACFramework.msi – https://www.sqlazurelabs.com/DACFramework.msi

5. SQLDom.msi – https://www.sqlazurelabs.com/SqlDom.msi

6. TSQLLanguageService.msi – https://www.sqlazurelabs.com/TSqlLanguageService.msi

After installing the prerequisites, extract the DacImportExportCli.zip to any directory ex. C:\DacImportExportCLI

Parameters Supported

-s – Server name

-d – Database name

-e – Integrated Authentication (For on-premise SQL Server)

-u – SQL User Name

-p – Password for SQL User name

-x – Export Schema and Data to bacpac file

-i – Import Schema and Data from bacpac file

-f – bacpac file , can be used as input and out based on –x or -i

-edition (Used for SQL Azure, Supported Values “business” or “web”)

-size – specify the Size of database in Gb ex. 1 (Used for SQL Azure to specify database size limit)

To Export Data and Schema

DacImportExportCli.exe –s ServerA.database.windows.net –d Northwind_DB –u dbuser –p password –f C:\DacImportExportCli\Northwind_DB_Backup.bacpac –x

image

To Import Data and Schema

DacImportExportCli.exe –s ServerB.database.windows.net –d Northwind_DB –u dbuser –p password –f C:\DacImportExportCli\Northwind_DB_Backup.bacpac –i

DacImportExportCli.exe –s ServerB.database.windows.net –d Northwind_DB –u dbuser –p password –f C:\DacImportExportCli\Northwind_DB_Backup.bacpac –i –edition web –size 1

image

To Remove a Database created using DAC Import

DacImportExportCli.exe –s ServerB.database.windows.net –drop Northwind_DB –u dbuser –p password

image

If you manually dropped a database using “DROP DATABASE” command for the database created using bacpac, the bacpac registration will still be available in server, you so you need to use –drop option to clear the registration, before reimporting it again 

Advantages:

1. Helps automating backup and restore process for SQL Azure

2. Helps automatic synchronizing between SQL Azure and SQL Server (On Premise) easily

Disadvantages:

1. The exported bacpac file contains the schema and data, not the log files, so it’s a not a real backup like the regular SQL Server backup file

For more information about DAC read the below white paper http://msdn.microsoft.com/en-us/library/ff381683(SQL.100).aspx 

Notes:

Do not install this if you have already installed SQL Server “Denali” CTP1

Advertisements
  1. ke
    June 16, 2011 at 5:48 am

    can DacImportExportCli be used for non-azure? e.g. sql server 2008?

    Like

    • June 16, 2011 at 7:33 am

      Good Question !!! Yes, we can use it for SQL Server 2008 R2 and Denali.

      I will test it on SQL Server 2005 and 2008 and post further information.

      If you explain you exact scenario, I can test and explain you.

      Like

  2. August 25, 2011 at 10:01 am

    .\DacImportExportCli.exe -S ONE -E -I -D veodin_content_2 -F veodin_content_one.bacpac

    Trying to import gives me an exception (I tried importing to my local SQL2008 and to Azure):

    [15:56:31] CreateDatabase: Pending Creating database ‘veodin_content_2’
    [15:56:31] CreateDatabase: Failure Creating database ‘veodin_content_2’ System.IO.FileNotFoundException: Could not load file or assembly ‘Microsoft.SqlServer.BatchParser, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845
    dcd8080cc91’ or one of its dependencies. The system cannot find the file specified.
    File name: ‘Microsoft.SqlServer.BatchParser, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91’
    at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
    at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
    at Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(String query, ExecutionTypes executionType, Int32& statementsToReverse)
    at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
    at Microsoft.SqlServer.Management.Dac.CreateDatabaseStep.Execute()
    at Microsoft.SqlServer.Management.Dac.TransactionalActionManager.ManagedActionStep.TransactionalStep.DoExecute()
    at Microsoft.SqlServer.Management.Dac.TransactionalActionManager.ManagedActionStep.Execute()

    Can you help?

    Like

  3. October 25, 2011 at 4:14 pm

    Hello Arunraj,

    First at all, thanks for your post. I’m trying to download the files from https://www.sqlazurelabs.com but I receive time out all the time… Do you know another site where I can download this msi’s?

    Thanks a lot!

    Like

  4. October 25, 2011 at 4:27 pm

    Never mind, I found it! 🙂 Thanks anyway ^^

    Like

  5. Thomas Forbes
    January 6, 2012 at 12:40 pm

    Thanks so much for this article! I’ve downloaded all that is listed here (including updates to the downloads, so not actually what is “here”) and attempted to do this from a “remote” server…meaning a server other than my SQL server 2008 r2. I get an error:
    Unhandled Exception: Microsoft.SqlServer.Management.Common.ConnectionFailureException: Failed to connect to server . —> System.Data.SqlClient.SqlException:A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

    Is is safe to assume that I need SQL client tools on my local server in order for it to reach the SQL server via the agent?

    Thanks in advance!

    mpleaf

    Like

    • January 6, 2012 at 1:53 pm

      Yes, you should have SQL Server Native Client Installed.

      Based on your error message, I would suggest you to verify whether Remote connections are enabled in your SQL Server and also Firewall is configured to allow SQL Server Access

      Hope this helps !!!

      Like

      • Thomas Forbes
        January 6, 2012 at 4:34 pm

        Thanks much again! I actually over cooked the problem. Decided to start at troubleshooting 101, and the ping to my SQL server didn’t work. 🙂 Resolved my DNS issue, and voila, all is right in the world, and the bacpac import worked like a charm.

        Like

    • mpleaf
      January 19, 2012 at 6:28 pm

      So, I was just wondering if you might be aware of an option to import as an “upgrade”? I know, you can upgrade using a dacpac, but I want to upgrade using a bacpac, to also prefill any new data that my new version of the db requires. I see nowhere the ability to do this…but hoping maybe command line option, or someone might be aware of a new version in planning that will allow to upgrade from one data-tier version to a newer, to include new data also.

      Thanks again, in advance!

      Like

      • January 20, 2012 at 6:09 am

        Hi Thomas,

        Currently it doesn’t support creating a package with only new data, for implementing something like that you need to use Data Compare tools such as Red Gate Data Compare, xSQL Data Compare, Visual Studio 2010 Data Compare, etc…

        Hope this clarifies your question !!!

        Like

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: