將資料庫註冊為 DACRegister a Database As a DAC

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

您可以使用 [註冊資料層應用程式精靈] 或 Windows PowerShell 指令碼來建立資料層應用程式 (DAC) 定義,以便描述現有資料庫中的物件,並在 msdb 系統資料庫 (在 Azure SQL DatabaseAzure SQL Database 中為 master) 中註冊 DAC 定義。Use either the Register Data-tier Application Wizard or a Windows PowerShell script to build a data-tier application (DAC) definition that describes the objects in an existing database, and register the DAC definition in the msdb system database (master in Azure SQL DatabaseAzure SQL Database).

開始之前Before You Begin

註冊程序會建立 DAC 定義,以定義資料庫中的物件。The registration process creates a DAC definition that defines the objects in the database. DAC 定義和資料庫的組合會形成 DAC 執行個體。The combination of the DAC definition and the database form a DAC instance. 如果將資料庫註冊為 Database Engine 執行個體上的 DAC,下次從執行個體將公用程式收集組傳送到公用程式控制點時,註冊的 DAC 將會合併到 SQL Server 公用程式中。If you register a database as a DAC on an instance of the Database Engine, the registered DAC will be incorporated into the SQL Server Utility the next time the utility collection set is sent from the instance to the Utility Control Point. 然後 DAC 會出現在 [公用程式總管] Management StudioManagement Studio [部署的資料層應用程式] 節點中,並在 詳細資料頁面中報告。The DAC will then be present in the Deployed Data-tier Applications node of the Management StudioManagement Studio Utility Explorer and reported in the Deployed Data-tier Applications details page.

限制事項Limitations and Restrictions

DAC 註冊只能在 SQL DatabaseSQL DatabaseSQL Server 2005 (9.x)SQL Server 2005 (9.x) Service Pack 4 (SP4) 或更新版本的資料庫上執行。DAC registration can only be performed on a database in SQL DatabaseSQL Database, or SQL Server 2005 (9.x)SQL Server 2005 (9.x) Service Pack 4 (SP4) or later. 如果已經針對資料庫註冊 DAC,將無法執行 DAC 註冊。DAC registration cannot be performed if a DAC is already registered for the database. 例如,如果資料庫是藉由部署 DAC 所建立,您將無法執行 [註冊資料層應用程式精靈] 。For example, if the database was created by deploying a DAC, you cannot run the Register Data-tier Application Wizard.

如果 DAC 或包含的使用者中不支援資料庫中的物件,則無法註冊 DAC。You cannot register a DAC if the database 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

Database EngineDatabase Engine 執行個體中註冊 DAC 至少需要 ALTER ANY LOGIN 和資料庫範圍 VIEW DEFINITION 權限、 sys.sql_expression_dependencies的 SELECT 權限,以及 dbcreator 固定伺服器角色的成員資格。Registering a DAC in an instance of Database EngineDatabase Engine requires at least ALTER ANY LOGIN and database scope VIEW DEFINITION permissions, SELECT permissions on sys.sql_expression_dependencies, and membership in the dbcreator fixed server role. 系統管理員 固定伺服器角色的成員或是內建 SQL Server 系統管理員帳戶 sa 也可以註冊 DAC。Members of the sysadmin fixed server role or the built-in SQL Server system administrator account named sa can also register a DAC. SQL DatabaseSQL Database 中註冊不包含登入的 DAC,需要 dbmanagerserveradmin 角色的成員資格。Registering a DAC that does not contain logins in SQL DatabaseSQL Database requires membership in the dbmanager or serveradmin roles. SQL DatabaseSQL Database 中註冊包含登入的 DAC,需要 loginmanagerserveradmin 角色的成員資格。Registering a DAC that contains logins in SQL DatabaseSQL Database requires membership in the loginmanager or serveradmin roles.

使用註冊資料層應用程式精靈Using the Register Data-tier Application Wizard

使用精靈註冊 DACTo Register a DAC Using a Wizard

  1. [物件總管] 中,展開含有要註冊為 DAC 的資料庫之執行個體的節點。In Object Explorer, expand the node for the instance containing the database to be registered as a DAC.

  2. 展開 [資料庫] 節點。Expand the Databases node.

  3. 以滑鼠右鍵按一下要註冊的資料庫,指向 [工作] ,然後選取 [註冊為資料層應用程式…] Right-click the database to be registered, point to Tasks, and then select Register As Data-tier Application...

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

    1. 簡介頁面Introduction Page

    2. 設定屬性頁面Set Properties Page

    3. 驗證與摘要頁面Validation and Summary Page

    4. 註冊 DAC 頁面Register DAC Page

簡介頁面Introduction Page

此頁面描述註冊資料層應用程式的步驟。This page describes the steps for registering a data-tier application.

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

下一步 > - 繼續進行 [設定屬性] 頁面。Next > - Proceeds to the Set Properties page.

取消 - 結束精靈,而不註冊 DAC。Cancel - Terminates the wizard without registering a DAC.

使用註冊資料層應用程式精靈Using the Register Data-tier Application Wizard

設定屬性頁面Set Properties Page

使用此頁面來指定 DAC 層級屬性,例如應用程式名稱和版本。Use this page to specify DAC-level properties such as the application name and version.

應用程式名稱Application name. - 字串,用來識別 DAC 定義的名稱,此欄位已經填入資料庫名稱。- A string that specifies the name used to identify the DAC definition, the field is been populated with the database name.

版本Version. - 可識別 DAC 版本的數值。- A numeric value that identifies the version of the DAC. DAC 版本會用於 Visual Studio 中,以便識別開發人員正在處理的 DAC 版本。The DAC version is used in Visual Studio to identify the version of the DAC that developers are working on. 部署 DAC 時,此版本會儲存在 msdb 資料庫中,而且您之後可以在 SQL Server Management StudioSQL Server Management Studio 的 [資料層應用程式] 節點底下檢視此版本。When deploying a DAC, the version is stored in the msdb database and can later be viewed under the Data-tier Applications node in SQL Server Management StudioSQL Server Management Studio.

描述Description. - 選擇性。- Optional. 說明 DAC 用途的文字。Text that explains the purpose of the DAC. 部署 DAC 時,此描述會儲存在 msdb 資料庫中,而且您之後可以在 Management StudioManagement Studio 的 [資料層應用程式] 節點底下檢視此描述。When deploying a DAC, the description is stored in the msdb database and can later be viewed under the Data-tier Applications node in Management StudioManagement Studio.

< 上一步 - 會讓您回到 [簡介] 頁面。< Previous - Returns you to the Introduction page.

下一步 > - 確認 DAC 可以從資料庫的物件建立而來,並在 [驗證與摘要] 頁面中顯示結果。Next > - Verifies that a DAC can be built from the objects in the database, and displays the results in the Validation and Summary page.

取消 - 結束精靈,而不註冊 DAC。Cancel - Terminates the wizard without registering the DAC.

使用註冊資料層應用程式精靈Using the Register Data-tier Application Wizard

驗證與摘要頁面Validation and Summary Page

使用此頁面來檢閱註冊 DAC 時,精靈將會採取的動作。Use this page to review the actions the wizard will take when registering the DAC. 當精靈驗證可以從資料庫中的物件建立 DAC 時,此頁面會在三種狀態之間轉換。The page transitions through three states as it verifies that a DAC can be built from the objects in the database.

使用註冊資料層應用程式精靈Using the Register Data-tier Application Wizard

擷取物件Retrieving Objects

擷取資料庫與伺服器物件。Retrieving database and server objects. - 當精靈從資料庫及 Database Engine 執行個體擷取所有必要的物件時,將會顯示進度列。- Displays a progress bar as the wizard retrieves all of the required objects from the database and the instance of the Database Engine.

< 上一步 - 回到 [設定屬性] 頁面來變更輸入。< Previous - Returns you to the Set Properties page to change your entries.

下一步 > - 註冊 DAC,並在 [註冊 DAC] 頁面中顯示結果。Next > - Registers the DAC and displays the results in the Register DAC page.

取消 - 結束精靈,而不註冊 DAC。Cancel - Terminates the wizard without registering the DAC.

使用註冊資料層應用程式精靈Using the Register Data-tier Application Wizard

驗證物件Validating Objects

Checking SchemaName .Checking SchemaName . ObjectName .ObjectName . - 當精靈驗證擷取之物件的相依性,並驗證這些對於 DAC 都是有效的物件時,將會顯示進度列。- Displays a progress bar as the wizard verifies the dependencies of the retrieved objects, and verifies that they are all valid objects for a DAC. SchemaName . ObjectName 識別目前正在驗證哪一個物件。SchemaName.ObjectName identify which object is currently being verified.

< 上一步 - 回到 [設定屬性] 頁面來變更輸入。< Previous - Returns you to the Set Properties page to change your entries.

下一步 > - 註冊 DAC,並在 [註冊 DAC] 頁面中顯示結果。Next > - Registers the DAC and displays the results in the Register DAC page.

取消 - 結束精靈,而不註冊 DAC。Cancel - Terminates the wizard without registering the DAC.

使用註冊資料層應用程式精靈Using the Register Data-tier Application Wizard

摘要Summary

下列設定將用來註冊 DAC。The following setting will be used to register your DAC. - 顯示將包含在 DAC 中的屬性和物件的報表。- Displays a report of the properties and objects that will be included in the DAC.

儲存報表 - 選取此按鈕可以將驗證報告複本儲存到 HTML 檔案。Save Report - Select this button to save a copy of the validation report to an HTML file. 預設資料夾為 Windows 帳戶之 [文件] 資料夾中的 SQL Server Management Studio\DAC Packages 資料夾。The default folder is a SQL Server Management Studio\DAC Packages folder in the Documents folder of your Windows account.

< 上一步 - 回到 [設定屬性] 頁面來變更輸入。< Previous - Returns you to the Set Properties page to change your entries.

下一步 > - 註冊 DAC,並在 [註冊 DAC] 頁面中顯示結果。Next > - Registers the DAC and displays the results in the Register DAC page.

取消 - 結束精靈,而不註冊 DAC。Cancel - Terminates the wizard without registering the DAC.

使用註冊資料層應用程式精靈Using the Register Data-tier Application Wizard

註冊 DAC 頁面Register DAC Page

此頁面會報告註冊作業成功或失敗。This page reports the success or failure of the registration.

註冊 DAC - 報告為了註冊 DAC 所採取的每個動作成功或失敗。Registering the DAC - Reports the success or failure of each action taken to register the DAC. 檢閱資訊以判斷每個動作成功或失敗。Review the information to determine the success or failure of each action. 發生錯誤的所有動作在 [結果] 資料行中都會有一個連結。Any action that encountered an error will have a link in the Result column. 選取連結來檢視該動作的錯誤報告。Select the link to view a report of the error for that action.

儲存報表 - 選取此按鈕可以將註冊報告儲存到 HTML 檔案。Save Report - Select this button to save the registration report to an HTML file. 此檔案會報告每個動作的狀態,包括所有動作所產生的所有錯誤。The file reports the status of each action, including all errors generated by any of the actions. 預設資料夾為 Windows 帳戶之 [文件] 資料夾中的 SQL Server Management Studio\DAC Packages 資料夾。The default folder is a SQL Server Management Studio\DAC Packages folder in the Documents folder of your Windows account. 檔案名稱格式為 <DACPackageName>_RegisterDACReport_yyyymmdd.html,其中 <DACPackageName> 是要部署之套件的名稱、yyyy = 目前的年份、mm = 目前的月份,而 dd = 目前的日期。The file name is in the format <DACPackageName>_RegisterDACReport_yyyymmdd.html, where <DACPackageName> is the name of the package being deployed, yyyy = the current year, mm = the current month, and dd = the current day.

完成 - 結束精靈。Finish - Terminates the wizard.

使用註冊資料層應用程式精靈Using the Register Data-tier Application Wizard

使用 PowerShell 註冊 DACRegister a DAC Using PowerShell

若要在 PowerShell 指令碼中使用 Register() 方法,將資料庫註冊為 DACTo register a database as a DAC using the Register() method in a PowerShell script

  1. 建立 SMO Server 物件,並將它設定為包含要註冊為 DAC 之資料庫的執行個體。Create a SMO Server object and set it to the instance that contains the database to be registered as a DAC.

  2. 加入可指定資料庫名稱的變數。Add a variable that specifies the name of the database.

  3. 指定 DAC 的中繼資料,例如 DAC 名稱、版本及描述。Specify the metadata for the DAC, such as the DAC name, version, and description.

  4. 使用上述指定的資訊執行 Register 方法。Run the Register method with the information specified above.

範例 (PowerShell)Example (PowerShell)

下列範例會將名稱為 MyDB 的資料庫註冊為 DAC。The following example registers a database named MyDB as a DAC.

## Set a SMO Server object to the default instance on the local computer.  
CD SQLSERVER:\SQL\localhost\DEFAULT  
$srv = get-item .  
  
## Specify the database to register as a DAC.  
$dbname = "MyDB"  
  
## Specify the DAC metadata.  
$applicationname = "MyApplication"  
$version = "1.0.0.0"  
$description = "This DAC defines the database used by my application."  
  
## Register the DAC.  
$registerunit = New-Object Microsoft.SqlServer.Management.Dac.DacExtractionUnit($srv, $dbname, $applicationname, $version)  
$registerunit.Description = $description  
$registerunit.Register()  

另請參閱See Also

資料層應用程式Data-tier Applications