views:

1190

answers:

2

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.

+3  A: 

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.

Richard L
I didn't spot the "since the app.config is compiled into the Windows Form" - good catch (+1)
Marc Gravell
Thanks, I think this is exactly what I want. I can use scripts to modify the exe.config file at installation time.
Ngu Soon Hui
A: 

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/

Raj Kashyap