Where would you recommend hiding or writing a connection string in a winforms desktop app? I have a DAL (data access layer) where I hardcoded it for the time being, but I know it shouldn't be there. Any tips on this? (I'm in VS 2017.)
A Resource file should work well for this.
Using Visual Studio, you can add one to a project by right-clicking the project and choosing "Properties", then go to the "Resources" tab and either create a default resource file (by clicking the link), or updating the existing resource file using the UI.
Once your project has a default resource file with key-value pairs in it, using values from the resource file in code is as simple as
Properties.Resources.AnyKeyYouDefinedInTheResourceFile
...where AnyKeyYouDefinedInTheResourceFile
is a key in the project's default resource file.
Note that the above example assumes that the code snippet is in the default namespace, since the full namespace for Properties
is really WhateverYourDefaultNamespaceIsCalled.Properties
.