Visual Database Tools
The Choose Your Data Connection page of the wizard is where you select the database to which you’ll be connecting the data source. The drop-down list is populated with all data connections already defined in both the application and the Server Explorer, but you can use the New Connection button to link to a database that is not listed. (Clicking the New Connection button displays the Add Connection dialog described previously.)
When you select the connection that Visual Studio is to use for the data source, the full connection string is displayed in the lower pane, enabling you to confirm that the database file you’re connecting to is the one you intended.
When you’re connecting to a SQL Server database file outside your project structure, Visual Studio warns you that it is outside the project definition. At this point, you can choose to copy the file to the project directory or use the existing file (see Figure 38-12).
Figure 38-12
The choice you make here has direct consequences on the execution of your application. If you choose to copy the file to the project directory, be aware that the database file will be included as part of the build process and copied to the project’s output folder every time you compile and run the application. This enables you to define a default set of data in the table, which can then be used as a basis for your testing of the application, rather than having to manually reset any changes you make during a debug session.
Conversely, if you choose not to copy the file, any changes you make during a debugging session are saved permanently to the database. If you choose to copy the database file into the project but do not want the database copied over each time you run the application, you can change the Copy to Output property of the database.
You can access the Properties page for a database file in your project via the Solution Explorer.
The last step is to choose which database objects should be included in the Data Source (see Figure 38-13). Expand the object types you wish to include and select the individual items that are to make up your Data Source.
As demonstrated in Figure 38-13, you can select a subset of fields from within a table (or a view), and you can include stored procedures and functions. You can access this page at a later stage by clicking the Configure DataSet with Wizard button at the top of the Data Sources window. When you’ve selected the objects, click Finish to have Visual Studio build the Data Source XML schema definition that controls how the data is used in your application.