How to change database when deploying application

  • Thread starter Thread starter harry
  • Start date Start date
H

harry

I've set my database connection as an Application.Setting using the
designer.

Since Application.Settings are read only, how do I change the connection
properties when deploying to another machine ?

Thanks
Harry
 
Perhaps you should put it as User Setting and then build a small form to
allow users to change db settings.
 
I know what the end users database is called and would prefer to avoid
additional work for user.

I would prefer to set dynamically when loading application.

I guess this is a common scenario and also guess one uses an XML file
deployed with the app.

Having used the designer to set the Connection string, and then built my
DataSet (again using designer) around that connection string I wonder why
the settings are ReadOnly when it's an obvious scenario for many developers.
I guess there's an obvious solution - one that I have yet to find.

Any other suggestions please ?
 
Sure a local XML file would be fine.

I guess I need to change the DataSet.DataSource as the program loads, but
not sure how at the moment.

Having already used the designer to create the connection and DataSet, how
do I go about doing this?

Would you know of a URL showing how do do this?

This must be a common scenario.
 
Since Application.Settings are read only, how do I change the connection
properties when deploying to another machine ?

I wish VS.NET had a way to inject deployment App.config keys... that would
solve this problem right? :-)
 
Hi Harry,

data in the app.config isn't readonly at all! It can be accessed through the
configurationmanager-class (but not by my.settings, that's right). Below you
find code I use to set the connection-string at runtime. Be aware of the
fact, that you can use more than one connectionstring in your config, hence
the SectName.

Public Shared Sub SetConnectString(ByVal SectName As String, ByVal
ConnectString As String, ByVal encrypt As Boolean)
Dim settings As New ConnectionStringSettings
settings.Name = SectName
settings.ConnectionString = ConnectString

Dim config As Configuration
config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
config.ConnectionStrings.ConnectionStrings.Remove(SectName)
config.ConnectionStrings.ConnectionStrings.Add(settings)
If encrypt Then

config.ConnectionStrings.SectionInformation.ProtectSection(Nothing)
End If
config.Save()
End Sub


HTH

Volker
 
Back
Top