匯出資料層應用程式Export a Data-tier Application

適用於: 是SQL Server 是Azure SQL Database 否Azure SQL 資料倉儲 否平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

匯出已部署的資料層應用程式 (DAC) 或資料庫,會建立匯出檔,而此檔案包含資料庫中物件的定義以及資料表中所含的所有資料。Exporting a deployed data-tier application (DAC) or database creates an export file that includes both the definitions of the objects in the database and all of the data contained in the tables. 接著,匯出檔可以匯入 Database EngineDatabase Engine的另一個執行個體或 Azure SQL DatabaseAzure SQL DatabaseThe export file can then be imported to another instance of the Database EngineDatabase Engine, or to Azure SQL DatabaseAzure SQL Database. 您可以合併匯出/匯入作業,以在執行個體之間移轉 DAC、建立封存或針對 SQL DatabaseSQL Database中所部署的資料庫建立內部部署複本。The export-import operations can be combined to migrate a DAC between instances, to create an archive, or to create an on-premise copy of a database deployed in SQL DatabaseSQL Database.

開始之前Before You Begin

匯出程序會使用兩個階段來建立 DAC 匯出檔。The export process builds a DAC export file in two stages.

  1. 匯出會在匯出檔 (BACPAC 檔案) 中建置 DAC 定義,其方式相當於 DAC 擷取在 DAC 套件檔案中建置 DAC 定義。The export builds a DAC definition in the export file - BACPAC file - in the same way a DAC extract builds a DAC definition in a DAC package file. 匯出的 DAC 定義包含目前資料庫中的所有物件。The exported DAC definition includes all of the objects in the current database. 如果匯出程序是針對原本從 DAC 部署的資料庫來執行,並已在部署之後直接變更資料庫,則匯出的定義會符合資料庫中所設定的物件,而非原始 DAC 中所定義的物件。If the export process is run against a database that was originally deployed from a DAC, and changes were made directly to the database after deployment, the exported definition matches the object set in the database, not what was defined in the original DAC.

  2. 匯出會大量複製資料庫中所有資料表的資料,並將資料合併至匯出檔。The export bulk copies out the data from all of the tables in the database and incorporates the data into the export file.

我們會持續聽取您的意見: 如果您發現本文中有過時或不正確的內容 (例如步驟或程式碼範例),請告訴我們。We are listening: If you find something outdated or incorrect in this article, such as a step or a code example, please tell us. 您可以按一下此頁面底部 [意見反應] 區段中的 [本頁] 按鈕。You can click the This page button in the Feedback section at the bottom of this page. 我們通常會在隔天閱讀有關 SQL 的每一個意見反應。We read every item of feedback about SQL, typically the next day. 謝謝。Thanks.

匯出程序會將 DAC 版本設定為 1.0.0.0,而將匯出檔中的 DAC 描述設定為空字串。The export process sets the DAC version to 1.0.0.0 and the DAC description in the export file to an empty string. 如果已從 DAC 部署資料庫,則匯出檔中的 DAC 定義會包含指定給原始 DAC 的名稱,否則,DAC 名稱會設定為資料庫名稱。If the database was deployed from a DAC, the DAC definition in the export file contains the name given to the original DAC, otherwise the DAC name is set to the database name.

限制事項Limitations and Restrictions

DAC 或資料庫只能從 SQL DatabaseSQL DatabaseSQL Server 2005 (9.x)SQL Server 2005 (9.x) Service Pack 4 (SP4) 或更新版本的資料庫中匯出。A DAC or database can only be exported from a database in SQL DatabaseSQL Database, or SQL Server 2005 (9.x)SQL Server 2005 (9.x) Service Pack 4 (SP4) or later.

如果 DAC 或包含的使用者中不支援資料庫的物件,則無法匯出資料庫。You cannot export a database that has objects that are not supported in a DAC, or contained users. 如需有關 DAC 中支援之物件類型的詳細資訊,請參閱< DAC Support For SQL Server Objects and Versions>。For more information about the types of objects supported in a DAC, see DAC Support For SQL Server Objects and Versions.

權限Permissions

您至少需具備 ALTER ANY LOGIN 和資料庫範圍 VIEW DEFINITION 權限,以及 sys.sql_expression_dependencies的 SELECT 權限,才能匯出 DAC。Exporting a DAC requires at least ALTER ANY LOGIN and database scope VIEW DEFINITION permissions, as well as SELECT permissions on sys.sql_expression_dependencies. 匯出 DAC 可以透過 securityadmin 固定伺服器角色的成員來完成,這個角色的成員也是匯出 DAC 之來源資料庫中 database_owner 固定資料庫角色的成員。Exporting a DAC can be done by members of the securityadmin fixed server role who are also members of the database_owner fixed database role in the database from which the DAC is exported. 系統管理員固定伺服器角色的成員或內建 SQL Server 系統管理員帳戶 sa 也可以匯出 DAC。Members of the sysadmin fixed server role or the built-in SQL Server system administrator account named sa can also export a DAC.

在 Azure SQL DB 上,您需要針對每個資料庫授與所有資料表或特定資料表的 VIEW DEFINITION 和 SELECT 權限On Azure SQL DB you need to grant for each database VIEW DEFINITION and SELECT permission on all tables or on specific tables

使用匯出資料層應用程式精靈Using the Export Data-tier Application Wizard

若要使用精靈匯出 DACTo Export a DAC Using a Wizard

  1. 連接到 SQL ServerSQL Server執行個體 (不論是內部部署或在 SQL DatabaseSQL Database中)。Connect to the instance of SQL ServerSQL Server, whether on-premise or in SQL DatabaseSQL Database.

  2. 在物件總管 中,展開您要匯出 DAC 的執行個體來源節點。In Object Explorer, expand the node for the instance from which you want to export the DAC.

  3. 以滑鼠右鍵按一下資料庫名稱。Right-click the database name.

  4. 按一下 [工作],然後選取 [匯出資料層應用程式...]Click Tasks and then select Export Data-tier Application...

  5. 完成精靈對話方塊:Complete the wizard dialogs:

簡介頁面Introduction Page

此頁面描述匯出資料層應用程式精靈的步驟。This page describes the steps for the Export Data-tier Application Wizard.

選項。Options

不要再顯示此頁面。Do not show this page again. - 按一下此核取方塊,之後就不會再顯示 [簡介] 頁面。- Click the check box to stop the Introduction page from being displayed in the future.

下一步 - 繼續進行 [Select DAC Package (選取 DAC 封裝)] 頁面。Next - Proceeds to the Select DAC Package page.

取消 - 取消作業並關閉精靈。Cancel - Cancels the operation and closes the Wizard.

匯出設定頁面Export Settings Page

請使用此頁面來指定要建立 BACPAC 檔案的位置。Use this page to specify the location where you want the BACPAC file to be created.

  • 儲存至本機磁碟 - 在本機電腦的目錄中建立 BACPAC 檔案。Save to local disk - Creates a BACPAC file in a directory on the local computer. 按一下 [瀏覽...] 巡覽本機電腦,或在提供的空間中指定路徑。Click Browse... to navigate the local computer, or specify the path in the space provided. 路徑名稱必須包含檔案名稱和 .bacpac 副檔名。The path name must include a file name and the .bacpac extension.

  • 儲存至 Azure - 在 Azure 容器中建立 BACPAC 檔案。Save to Azure - Creates a BACPAC file in an Azure container. 您必須連線到 Azure 容器,才能驗證此選項。You must connect to an Azure container in order to validate this option. 請注意,此選項也會要求您指定暫存檔的本機目錄。Note that this option also requires that you specify a local directory for the temporary file. 請注意,暫存檔將建立在指定的位置,而且作業完成之後,將保留在該位置。Note that the temporary file will be created at the specified location and will remain there after the operation completes.

若要指定要匯出的資料表子集,請使用 [進階] 選項。To specify a subset of tables to export, use the Advanced option.

驗證頁面Validation Page

您可以使用 [驗證] 頁面來檢閱封鎖作業的任何問題。Use the validation page to review any issues that block the operation. 若要繼續進行,請解決封鎖問題,然後按一下 [重新執行驗證] 確定驗證成功。To continue, resolve blocking issues and then click Re-run Validation to ensure that validation is successful.

若要繼續進行,請按 [下一步]To continue, click Next.

摘要頁面Summary Page

您可以使用此頁面來檢閱作業的指定來源和目標設定。Use this page to review the specified source and target settings for the operation. 若要使用指定的設定來完成匯出作業,請按一下 [完成]。To complete the export operation using the specified settings, click Finish. 若要取消匯出作業並結束精靈,請按一下 [取消]。To cancel the export operation and exit the Wizard, click Cancel.

進度頁面Progress Page

此頁面會顯示進度列,指出作業的狀態。This page displays a progress bar that indicates the status of the operation. 若要檢視詳細狀態,請按一下 [檢視詳細資料] 選項。To view detailed status, click the View details option.

結果頁面Results Page

此頁面會報告匯出作業成功或失敗,並顯示每個動作的結果。This page reports the success or failure of the export operation, showing the results of each action. 發生錯誤的所有動作在 [結果] 資料行中都會有一個連結。Any action that encountered an error will have a link in the Result column. 按一下連結,即可檢視該動作的錯誤報告。Click the link to view a report of the error for that action.

按一下 [完成] 關閉精靈。Click Finish to close the Wizard.

使用 .Net Framework 應用程式Using a .Net Framework Application

在 .Net Framework 應用程式中使用 Export() 方法,匯出 DAC。To export a DAC using the Export() method in a .Net Framework application.

若要檢視程式碼範例,請下載 Codeplex上的 DAC 範例應用程式。To view a code example, download the DAC sample application on Codeplex

  1. 建立 SMO Server 物件,並將它設定為包含要匯出之 DAC 的執行個體。Create a SMO Server object and set it to the instance that contains the DAC to be exported.

  2. 開啟 ServerConnection 物件,並連接到相同的執行個體。Open a ServerConnection object and connect to the same instance.

  3. 使用 Microsoft.SqlServer.Management.Dac.DacStore 類型的 Export 方法,匯出 DAC。Use the Export method of the Microsoft.SqlServer.Management.Dac.DacStore type to export the DAC. 指定要匯出之 DAC 的名稱,以及要放置匯出檔之資料夾的路徑。Specify the name of the DAC to be exported, and the path to the folder where the export file is to be placed.

另請參閱See Also

資料層應用程式 Data-tier Applications
從資料庫中擷取 DACExtract a DAC From a Database