Home > Articles > Programming > Windows Programming

Visual Studio.NET Database Projects

  • Print
  • + Share This
  • 💬 Discuss
Database projects are special types of Visual Studio.NET projects which help you create and manage SQL database scripts. The Visual Database tools allow you to view, design, modify, and test database objects (for example, tables, views, queries, stored procedures, and so on) without having to jump from the Visual Studio environment to a different toolset. This chapter shows how to use some of the Visual Database tools in a VS.NET database project.

The database project is a special type of Visual Studio.NET project. Its purpose is to create and manage SQL database scripts. If you're developing database applications with Visual Studio.NET, you will want to know about the tools available for making your work with databases easier and faster. This version of Visual Studio features many new tools and contains significant improvements to others that existed in previous versions.

The Visual Database tools allow us to view, design, modify, and test database objects (for example, tables, views, queries, stored procedures, and so on) quickly without having to jump from the Visual Studio environment to a different toolset. The main advantage is in design and development productivity, although licensing and installation issues also have been greatly simplified.

We have already worked with some of these tools in previous chapters, and their use is usually quite intuitive. They should also seem very familiar to you if you've had experience using similar tools (even MS Access qualifies). If this is your first time working with such tools, the Visual Studio help topics will be useful.

In this chapter we continue using some of the Visual Database tools to demonstrate how to utilize the tools and features available in a VS.NET database project.

Creating a Database Project

A special type of VS.NET project of particular interest is the database project. A database project is not specific to any .NET programming language, such as Visual Basic or C#, but is meant to be used to design, test, run, and manage SQL scripts and queries. When you design your application in multiple layers, as you should, this project type helps you to develop and manage the database layer closest to the database and the database itself.

In some applications, a database project may be part of the actual application code, and in other applications, it may be part of a separate administration solution used to set up and maintain the application's database.

To add a new database project to a solution, do the following.

  1. Launch the Add New Project dialog from either the main File menu or from the context menu displayed by right-clicking on the solution in the Solution Explorer.

  2. The left panel of this dialog box displays a list of folders containing different project types. Expand the Other Projects folder (click on the "+").

  3. Select the Database Projects folder. It displays a Database Project template in the right panel of the dialog box.

  4. Specify a project name of NoveltyData and a path for saving the project files and then click on the OK button.

  5. If you don't currently have any database connections defined in the Server Explorer, the Data Link Properties dialog box will be displayed, allowing you to define a new database connection.

  6. If you have at least one database connection defined in the Server Explorer, the Add Database Reference dialog box is displayed. From this dialog choose the database connection that you want to use (you can add new ones later). Alternatively, you can click on the Add New Reference button to display the Data Link Properties dialog box, allowing you to define a new database connection.

  7. Select the connection to the Novelty database on the SQL Server and click on the OK button. If for some reason the connection doesn't exist, create it from the Data Link Properties dialog box.

  8. Figure 8.1 shows the project and its folders in the Solution Explorer.

    Figure 1Figure 8.1 The NoveltyData database project shown in the Solution Explorer


Note that the created database project contains the following folders:

  • Change Scripts

  • Create Scripts

  • Queries

  • Database References

Let's take at look at these folders and what they contain. We start with Database References because they're the prerequisite for everything else.

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus