You really can save it in the application configuration file (see @NoOne answer for more details). However, remember that you probably should not store your username and password here.
You have the following options:
(a) encrypt the connectionStrings configuration section. This has some administrative βproblemsβ since you discovered YMMV.
(b) do not save the username and password, but request them from the user at run time; optionally allowing them to be specified as command line parameters, although it has its own problems: the parameters (and therefore the username / password) will be visible using viewing tools such as Task Manager or Process Explorer.
(c) check if you can change the connection credentials from the username / password to integrated security (you do not need to specify the username / password in the connection string and therefore not in the configuration file).
Option (c) is the best. This eliminates the need for a username (and, more importantly) a password in general. However, your application (and environment) should be prepared for this (more details here ).
If you select option (b), you can specify the connection string in the configuration without the User and Password keys. You would allow the user to specify them and then create a real connection string for future use using the SqlConnectionStringBuilder (or DbConnectionStringBuilder ) class:
var builder = new SqlConnectionStringBuilder( ConnectionManager.ConnectionStrings["test"].ConnectionString); builder.UserID = builder.Password = string realConnectionString = builder.ConnectionString;
source share