Graviton
Graviton

Reputation: 83326

Modifying the Data Source for the Strongly Typed Dataset connection string

Here are two questions related to modifying the data source for strongly typed dataset connection string.

When my app is deployed, a light weight database ( in the form of Microsoft Access) is deployed to the Application Data folder. I have a strongly typed dataset that is wrapped around that. So the question is how to change the following app.config code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="XTrace.Properties.Settings.Timer_DBConnectionString"
            connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot;|DataDirectory|\Timer DB.mdb&quot;;Persist Security Info=True"
            providerName="System.Data.OleDb" />
    </connectionStrings>
</configuration>

To make it read from the Application Data folder copy?

I read from SO and elsewhere that it's best to use app.config or web.config to manage the connection string. But since the app.config is compiled into the Windows Form, how does it suppose to provide the flexibility that allows one to change the connection string at deployment time? I am not talking about web app though, because I understand that it's possible that web app distributes the web.config and from that file you can modify your connection string.

Upvotes: 1

Views: 3012

Answers (3)

FrenkyB
FrenkyB

Reputation: 7217

For class libraries: every project's setting in app.config must also be changed in .settings file. That means: if you change only app.config, you have to check Project -> Properties. In VS2012 changes between app.config and .settings file are immediately shown and possibility offered to accept those changes. Without this (so change only app.config file), changes will not take effect.

Settings are embedded into class library (example below), so when referencing one there is no .config file.

Class library with embedded changes

Upvotes: 0

Raj Kashyap
Raj Kashyap

Reputation: 81

Instead of modifying .config file, you might be better off adding a new connection string property at runtime and using the TableAdapterManager. Please read more at: http://rajmsdn.wordpress.com/2009/12/09/strongly-typed-dataset-connection-string/

Upvotes: 1

Richard L
Richard L

Reputation: 1221

When you deploy an Windows Forms application you could have an app.config file.

yourproject.exe gives you a yourproject.exe.config file, which is the app.config file.

Upvotes: 5

Related Questions