26.04.2015 Views

Team Development with Visual Studio Team Foundation Server

Team Development with Visual Studio Team Foundation Server

Team Development with Visual Studio Team Foundation Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

correct when creating builds for production releases and for any test environments. As<br />

part of this build setup, the appropriate User.confg file must be retrieved from the source<br />

control system and copied into the correct location for MSBuild to be able to find it.<br />

Referencing Databases<br />

Database references in the form of connection strings can also be managed by using an<br />

external configuration file. The advantage of this approach is that each developer can<br />

easily specify his or her own connection string in their own private User.config file. Any<br />

changes made by one developer, such as redirecting the connection to a local database for<br />

unit testing purposes, do not affect other developers.<br />

User configuration files can also be used to control environment-specific settings, such as<br />

those required by a test environment. The test environment can also use a User.config file<br />

that references the test database.<br />

The procedure is similar to the preceding Web references example, except that in that<br />

example the Web service proxy contains the code to retrieve the Web service URL from<br />

the configuration file. For database connection strings, you must provide the code to read<br />

the connection string.<br />

How to Use User Configuration Files for Database Connection Strings<br />

The following procedure explains how to store and then reference a database connection<br />

string <strong>with</strong>in a user configuration file.<br />

To use a user configuration file to store database connection strings:<br />

1. Add a configSource="user.config" attribute to the element of<br />

your main application configuration file.<br />

<br />

<br />

<br />

2. To override the main application configuration file, create a User.config file (located<br />

in the same folder as the application configuration file), and then add a similar<br />

entry to the file. Notice that the following connection string<br />

references a local database.<br />

<br />

<br />

<br />

<br />

3. Within your project, use the following code to obtain the connection string from the<br />

user configuration file. This code uses the static ConnectionStrings property of the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!