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.
Asked
Active
Viewed 1,159 times
5 Answers
1
string connectionString = String.Empty;
#if DEBUG
connectionString = ..
#else
connectionString = ..
#endif

abatishchev
- 98,240
- 88
- 296
- 433
0
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
- 829
- 1
- 7
- 16
0
If Environment.UserInteractive Then
'Dev
Else
'Prod
End If