Dynamic ConnectionString

Mganda

New member
Joined
Apr 29, 2021
Messages
1
Programming Experience
5-10
I want to create a dynamic ConnectionString for my WinForms application to an SQL server, the user should set it up on first app use. How would I go about it? Will this be ultimately saved in App.config?
 
Connection strings created via the Settings page of the project properties are stored in the primary config file. That file is effectively read-only. You can use User-scoped settings, in which case the data is stored in the user config file, which is read/write. It just means that if your app is run by multiple Windows users, they will each have separate settings. That's probably want you would want anyway though.

So, open the Settings page of the project properties and add a string setting with User scope. You can provide a default value if you want or not. At run time, you access it via Properties.Default.Settings (off the top of my head, might be Properties.Settings.Default). I would suggest that you use a SqlConnectionStringBuilder to combine and separate the individual components of the connection string.
 
Back
Top Bottom