VS2005 - ConnectionString - DesignTime - Change at Runtime

  • Thread starter Thread starter Michael Moreno
  • Start date Start date
M

Michael Moreno

Hi,

We have an app that is made of many exes (WinForms and Win32 app).

All those exes share and read their DB connection string from the
registry. This guarantees that all the exes use the same DB.

With .Net the connection string is in the app.config file as soon as
you use the design time functionality to bind data to grids as an
example. So when you have 20 exes you have 20 app.config and the
possibility to use 20 different connection string which is really bad!

So I want to use that shared and common DB connection string. The
problem is that it seems we either have the choice of writing all the
code manually in which case we can control the connection string or
using the design time functions of VS but then we lose control of the
connection string which goes into the app.config file.

The question is how can you still use the VS.Net design time function
but make sure that you can when the app start specify the connection
string you want and not the one in the app.config?

I can see that in the data adapters the auto-generated code specifies:

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
private void InitConnection() {
this._connection = new
System.Data.SqlClient.SqlConnection();
this._connection.ConnectionString =
global::ForecastSkillVerification.Properties.Settings.Default.Speed_62_MM_GOODConnectionString;
}

Therefore it seems that if there is a way to override the value of:
global::ForecastSkillVerification.Properties.Settings.Default.Speed_62_MM_GOODConnectionString
at the start of the program then my problem would be solved.

Unfortunately
global::ForecastSkillVerification.Properties.Settings.Default.Speed_62_MM_GOODConnectionString
is read-only.

Any solutions to these guys?

thanks,
M
 
| [System.Diagnostics.DebuggerNonUserCodeAttribute()]
| private void InitConnection() {
| this._connection = new
| System.Data.SqlClient.SqlConnection();
| this._connection.ConnectionString =
|
global::ForecastSkillVerification.Properties.Settings.Default.Speed_62_MM_GOODConnectionString;
| }
|
| Therefore it seems that if there is a way to override the value of:
|
global::ForecastSkillVerification.Properties.Settings.Default.Speed_62_MM_GOODConnectionString
| at the start of the program then my problem would be solved.
|
| Unfortunately
|
global::ForecastSkillVerification.Properties.Settings.Default.Speed_62_MM_GOODConnectionString
| is read-only.
|
| Any solutions to these guys?

Just do something like:

this._connection.ConnectionString = "myconnectionString";
 
Simple solution would be to put the connect information in a common location
like All User's Application specific datapath, and make all applications
look for it there.

This is available from
Enviroment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) <-
lets you see the above.. works from .NET apps..., and sure there is a way to
read in Win32apps, I am just not sure of syntax

VJ
 
Just do something like:
this._connection.ConnectionString = "myconnectionString";

Yes thanks.
But this code has been automatically generated hence if I modify it VS
may change it, may it not ?
 
Back
Top