Question Choose the right connection string

ADH

Member
Joined
Apr 17, 2005
Messages
22
Location
ISRAEL
Programming Experience
10+
I need more then 1 (MS-SQL) connection string/configuration, depending on the current running configuration (Development, Production, offline etc.)
How could I declare these connection strings in advance (Proj. Settings) and tell the application which one to use without the need to compile the program.
Using a command-line argument is an option but still unconvenient.
I know .NET/ASP has an 'outside' non-comipied config file used by the application which you can modify.
Any thing like for a Win Form/Smart desck top application?
Thanks
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,393
Location
Sydney, Australia
Programming Experience
10+
Open the Settings page of the project properties. There you can add as many connection strings as you like. The name of each one will be added as a property of My.Settings. You can then choose which one to use in whatever way is appropriate, e.g.
VB.NET:
Select Case dataMode
    Case DataMode.Development
        connectionString = My.Settings.DevelopmentConnectionString
    Case DataMode.Production
        connectionString = My.Settings.ProductionConnectionString
End Select
 

ADH

Member
Joined
Apr 17, 2005
Messages
22
Location
ISRAEL
Programming Experience
10+
DataMode?

This is just the point of my question: From where do I get the "DataMode" (command argument? unconvinient, recompile? even less)
Thanks
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,393
Location
Sydney, Australia
Programming Experience
10+
That's completely up to you. If you're not going to recompile then it has to be outside the compiled code, but exactly where is for you to choose. Maybe it's in the config file. Maybe it's stored in My.settings, which uses the config file anyway. Maybe it comes from some other external source.
 
Top Bottom