Bagikan melalui


How to: Import Server Objects and Settings

You can manage changes to objects and settings on a database server by creating a server project, importing the objects and settings into it, and putting it under version control. If you use the New Database Project Wizard, you can specify a server from which to import objects and settings when you create the project. You can import objects and settings by using the Import Database Wizard or by using an automation command from the Command Window. For more information, see How to: Create Database and Server Projects. As an alternative, you can create an empty server project and import objects and settings later.

Required Permissions

You must have permissions to access the server from which you want to import objects and settings. In many development environments, the person in the role of the database administrator creates the server project and imports the objects and settings. That person then hands the project off to the team for development work.

To import server objects and settings by using the Import Database wizard

  1. Either create a server project or open an existing one that does not already contain objects. For more information, see How to: Create Empty Database and Server Projects.

    Solution Explorer displays the solution that contains the server project.

  2. In Schema View, click the server project into which you want to import objects and settings.

    If Schema View does not appear, open the View menu, and click Database Schema View.

  3. On the Project menu, click Import Objects and Settings.

    The Import Database wizard appears.

  4. In Source database connection, click the connection through which you want to import objects and settings. If no connection appears, click New Connection to create a connection.

    You can create a connection in Server Explorer or other places in Visual Studio Premium. For more information, see How to: Create a Database Connection.

  5. (Optional) Under Import options, do one or more of the following:

    1. You can limit when column collations are explicitly specified to only those cases in which the column collation does not match the database collation. To create this limitation, select the Script the column collation only if it is different from the database collation check box. Otherwise, clear that check box.

    2. If you want to import extended properties on the source database and its contents, select the Import Extended Properties check box. Otherwise, clear that check box.

      For example, you can import a table that is named MyTable. This action will add sp_addextendedproperty statements to the MyTable.table.sql file. These statements include sp_addextendedproperty, sp_settriggerorder, sp_tableoption, and sp_indexoption. For more information, see this topic on the Microsoft Web site: sp_addextendedproperty (Transact-SQL).

    3. If you want to import the sizes for log files and filegroups, select the Import log and filegroup file sizes check box. Otherwise, clear that check box.

    4. If you want to import permissions from the source database, select the Import permissions check box. Otherwise, clear that check box.

      If you import permissions, you can specify whether those permissions are added to the model of the database project. If you add the permissions to the model, your database project will load more slowly.

    5. If you want to update the settings for the database project to match the settings for the source database, select the Override database configuration with imported schema settings check box. Otherwise, clear that check box.

    6. You can decrease the amount of time that it takes to open and work with your database project by limiting the number of database objects that are stored in each folder in your project. In the Maximum files per directory list, click the number of files that you want to allow in a single directory on disk.

  6. Click Start to import the objects and settings.

    Important

    If you import objects and settings from a database other than "master", the following warning appears: "If you import database objects into this server project and then deploy this project, you will also deploy those objects to the 'master' database. Are you sure that you want to import database objects into this server project?"

    The Error List window displays any errors that relate to the objects that you import. The status bar in Visual Studio indicates when all the objects and settings have been imported. Other errors appear on the wizard summary page and are also written to a log file in the project folder.

  7. You must configure your project settings before you can build and deploy your project. For more information, see Build and Deploy Databases to an Isolated Development Environment.

To import server objects and settings by using the Visual Studio automation model

  1. Either create or open a server project that does not already contain database objects.

    For more information, see How to: Create Empty Database and Server Projects.

    Note

    You can create a project and import a schema at the same time by using the New Database Project Wizard. For more information, see How to: Create Database and Server Projects.

  2. Open the View menu, point to Other Windows, and click Command Window.

  3. In the Command Window, type the following command:

    Project.ImportDatabaseSchema /ConnectionString "YourConnectionInfo"
    

    Replace YourConnectionInfo with the connection string that you use to connect to the database from which you want to import. When you import server objects and settings, you should specify the "master" database in your connection string.

    Note

    You can specify additional options for the command that control the import operation. For more information, see Automation Command Reference for Database Features of Visual Studio. If you do not specify a connection, the Import Database wizard appears.

    The objects and settings are imported from the specified server into the database project that was selected in Solution Explorer when you executed the command. The Error List window displays any errors that relate to the objects that are imported.

    At this point, you must configure your server project settings before you can build and deploy your project. For more information, see How to: Configure Server Properties for Server Projects.

See Also

Tasks

How to: Import Database Objects from a Script

How to: Create Database and Server Projects