Just wondering what the general opinion is for storing connections strings in a windows application? As a separate class or in the app.config file?
Printable View
Just wondering what the general opinion is for storing connections strings in a windows application? As a separate class or in the app.config file?
Master DB access isn't necessary, so user ID in config file is usually good enough. User logs in after that
What do you mean by "as a separate class"?
As a completely different class file
Let's clear up something - class has nothing to do with file. You can have multiple classes in one file. You can also use the 'partial' class keyword and have one class span many files. When talking about classes, what file the class resides in is irrelevant (because after compiling the source files are no longer in use).
Are you talking about hardcoding the connection string into a member of the class? If so, this should be avoided.
Thank you for your input
One last question.
How would I use the app.config file if the location of the DB is dependant on where the application launches.
Example: The application is a portable app designed to be run on a thumb drive.
You are better of using some other criteria to determine an app configuration rather than the install location of the app.
For example, if you app launches from the thumb drive, then write a LaunchMode setting in the app.config and set it to ThumbDrive.
There are many ways to accomplish the same thing - basing an app's action on where it's installed from is rarely a good thing.
Thank you. Is there perhaps a few articles that you can direct me to for some reading/studying.