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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

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

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

it.<br />

Additional Resources<br />

• For more information, see “Web Projects and Source Control Integration in <strong>Visual</strong><br />

<strong>Studio</strong> .NET” at http://msdn2.microsoft.com/en-US/library/aa290068(VS.71).aspx<br />

• For more information about the ApplicationSettingsGroup class, see<br />

“ApplicationSettingsGroup Class” at http://msdn2.microsoft.com/enus/library/system.configuration.applicationsettingsgroup.aspx<br />

How to Manage Database Dependencies<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 as follows:<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.<br />

Notice that the following connection string 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.<br />

This code uses the static ConnectionStrings property of the<br />

System.Configuration.ConfigurationManager class. In the Win Form application,<br />

you must add a reference to System.Configuration.dll explicitly.<br />

using System.Configuration;<br />

private string GetDBaseConnectionString()<br />

{<br />

return ConfigurationManager.ConnectionStrings["DBConnStr"].ConnectionString;<br />

}

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

Saved successfully!

Ooh no, something went wrong!