Lesson 1: Creating a DAC in Visual Studio

In this lesson, you will create a sample DAC project in Visual Studio 2010, and then build the DAC package used in the following lessons. All of the steps in this lesson are performed in Visual Studio.

Procedures

Create a DAC Project in Visual Studio

  1. Open Microsoft Visual Studio.

  2. On the File menu, point to New, and click Project.

  3. In the New Project dialog box, under Installed Templates, expand the Database node, and then click the SQL Server node.

  4. In the list of templates, click Data-tier Application.

  5. In Name, type SampleDAC.

  6. Accept the default Location and Solution Name.

  7. Select the Create directory for solution check box if it is not already selected.

  8. Clear the Add to Source Control check box if it is not already cleared, and click OK.

    The SampleDAC project is created.

    Next, you will edit the project properties.

Configure the DAC Project

  1. View the Solution Explorer to confirm that the SampleDAC project has been created and is open.

  2. View the Schema View to confirm that the SampleDAC project is available there.

  3. In Solution Explorer, expand the SampleDAC node, right-click the Properties node and select Open.

  4. On the Project Settings tab, observe the default settings, but do not change them for this tutorial.

  5. Select the Build tab. If you wish to change the collation of the database created when you deploy the DAC, select the new collation in the Database collation box. Observe the other settings, but do not change them. With these settings, a build of the project creates a SampleDAC.dacpack file for deploying the DAC.

  6. Select the Build Events tab. Observe the available settings, but do not change them.

  7. Select the Deploy tab. These settings control the actions if you deploy the DAC from Visual Studio. Click the Edit button beside the Destination connection string box. This opens a Connect to SQL Server dialog box. In the connection dialog, fill in the connection information for an instance of the Database Engine running SQL Server 2008 Service Pack 2 or later. When you click OK, the dialog box builds a connection string and places it in the Destination connection string box on the Deploy tab.

  8. Select the Code Analysis tab. Observe the set of rules you can enable if you perform a code analysis of the DAC project, but do not change them.

  9. Close the project properties dialog box.

    You have now created a SampleDAC project and configured its properties.

  10. Next, you will configure the server selection policy.

Configure the Server Selection Policy

Data-tier applications include a server selection policy that defines the criteria that an instance of the SQL Server Database Engine should meet to host the DAC. The database administrator can choose to ignore the policy evaluation results when they deploy the DAC.

To Configure a Server Selection Policy

  1. In Solution Explorer, expand the SampleDAC node, and then expand the Properties node. Right-click Serverselection.sqlpolicy, and then click Open.

  2. In the Facet properties pane, select IsCaseSensitive.

  3. In the Edit values dialog box, set the Value property to either True or False, to match the default collation of the instance of the Database Engine where the DAC is to be deployed.

  4. Click the OK button.

    You have now configured the server selection policy to test whether the default collation of an instance of the Database Engine is case-sensitive.

    Next, you will add a table to the project.

Adding a Table and Building the DAC

Now that the DAC project is configured, the following steps illustrate adding objects to the project, then building and deploying the DAC package.

To add a table to the project

  1. In Schema View, expand the SampleDAC node, expand the Schemas node, and expand the node for the dbo schema.

  2. Right click the Tables node, select Add, and then Table.

  3. In the Add New Item dialog, ensure that the Table template is selected, and change the value in the Name box at the bottom of the dialog box to read Customer. Click the Add button. A Transact-SQL Editor window is now open for a file named SampleTable.table.sql.

  4. In the Transact-SQL Editor window, edit the CREATE TABLE statement to read:

    CREATE TABLE [dbo].[Customer]
    (
        [CustomerID]   INT           PRIMARY KEY,
        [CustomerName] NVARCHAR(40)  NOT NULL,
        [YTDOrders]    INT           NOT NULL,
        [YTDSales]     INT           NOT NULL
    );
    
  5. Close the Transact-SQL Editor, saving your changes. In Schema View, you should now see a Customer table under the dbo node. In Solution Explorer you should now see a Customer.table.sql file.

    You have now added a table to the SampleDAC project, and can build the project.

To build the project

  1. In Solution Explorer, right-click the SampleDAC node, and select Build.

  2. In the Output window, review the report of the build actions. One of the items reported is the path and name of the SampleDAC.dacpac file created by the build.

  3. If the instance of the Database Engine where you will upgrade the DAC is on a separate computer, copy the SampleDAC.dacpac file to a location that can be accessed from the other computer.

    You have now built the SampleDAC project. You can hand off the .dacpac file to a developer or database administrator, who can then use the Import Data-tier Application Wizard in SQL Server Management Studio to deploy the DAC to an instance of the Database Engine.

Next Steps

You have successfully created a sample DAC project and built a DAC package. Next, you will deploy the DAC to an instance of the Database Engine. See Lesson 2: Deploying a Data-tier Application.