I have a vs winform application which gets its datasources from a configuration file (app.config). I had connections to several databases. I have now removed some of them so that I am remaining with only one database and one connection string.
However, when I run a loop to retrieve connection strings from app.config file, I get the current connection string and all the others which I have deleted, which is confusing for what I am trying to implement.
I have ensured the old connection strings are deleted from app.config file, I have ensured they are not listed in the Settings section of the project properties, I have deleted the app.exe.config file in the bin folder and built the project afresh, but these old connection strings still show up in my code.
This is the code I am using to check:
Dim conCollection As ConnectionStringSettingsCollection = _
conCollection = ConfigurationManager.ConnectionStrings()
For Each cs As ConnectionStringSettings In conCollection
MsgBox(cs.ConnectionString)
Next
Results: I am getting 6 connection strings instead of one.
What is the procedure to removing existing and previous connection strings so that they are not picked up by the code above.
Thanks.
Check how and when you initialize and/or insert the Strings into conCollection
. You have to make sure you initialize the collection with the correct Strings on startup or you overwrite the collection on runtime once you made your changes to the file.