views:

183

answers:

4

In my VB.NET windows application code I created my own AppConfig class that holds the connection string to a SQL server database. I am about to move this program into production and was wondering if there is an easy way to have the program switch between a development connection string and a production connection string based on whether I am running the program through VS or running the deployed program. I was looking at preprocessing directives but couldnt figure it out. Thanks for the help.

+1  A: 
string connectionString = String.Empty;
#if DEBUG
connectionString = ..
#else
connectionString = ..
#endif
abatishchev
A: 

You can use preprocessing directives like #debug to run certain blocks of code only while in debug mode but those are only available in C# I believe. I think you'll have to look at another way of doing that in VB without having to touch your code. Is it possible to use different config files with the different config info on them for each environment?

-Bryan

Bryan Corazza
A: 

Please check this post with a similar discussion where the question was to use the appropriate app config depending on the build configuration.

I will be little hesitant to use the directive approach you want to take.

Biswanath
A: 
If Environment.UserInteractive Then
  'Dev
Else
  'Prod
End If