Rule #17
Do you hard code your ConnectionString?
  v3.0 Posted at 20/10/2010 7:56 PM by system
We don't like hard coded string inside our programme. We are using model-driven development, in which we create or reuse code, and perform changes in configuration file rather the in-code changing. More information on implementing our configuration.
connection.ConnectionString = "
Provider=SQLOLEDB;
Data Source=server_name_or_address; Initial Catalog=database_name;
User ID=username; Password=password; ";

   connection.Open();
Bad code - use the lengthy connection string.
connection.ConnectionString = ConfigurationManager.Items["ConnectionString"];

 connection.Open();
Figure: Good Code - Use ConfigurationManager to handle the connection string.
We have a program called SSW Code Auditor to check for this rule.
 


Related rules