c# - Where to save SQL Server connection string in a client console application? -
i creating windows console application monitor attendance of users. when user logging in computer(connected network) windows login time should updated in sql server database.
all client computers connected using network.
the question save database connection string server? if save connection string (encrypted) in console application running in client application, create problem if there change in server name/username/password after few months.
please advice best approach problem.
you indeed store in application configuration file (see @noone's answer more details). however, mind should not store username , password there.
you have following options:
(a) encrypt connectionstrings
configuration section. has administrative "issues" have discovered ymmv.
(b) don't store username , password, query them user during runtime; optionally allowing them specified command line parameters - although has issues of own: parameters (and username/password) visible using process viewer tools task manager or process explorer.
(c) see if can change connection credentials username/password integrated security (thus don't need put username/password in connnection string , thereby not in configuration file).
option (c) best. removes necessity of username (and more importantly) password altogether. however, application (and environment) must prepared (more here).
if go option (b), specify connection string in configuration without user
, password
keys. let user specify them , buildup real connection string use further on utilizing sqlconnectionstringbuilder
(or dbconnectionstringbuilder
) class:
var builder = new sqlconnectionstringbuilder( connectionmanager.connectionstrings["test"].connectionstring); builder.userid = /* username specified user */ builder.password = /* password specified user */ string realconnectionstring = builder.connectionstring;
Comments
Post a Comment