Rule Definition
Direct access to the database from the User Interface does not respect the multi-layer architecture principles making the application more difficult to change.
Furthermore, accessing database elements directly from the User Interface prevents access control at the database level . E.g.: use of non-optimized query against the database and can be the source of performance issue.
Remediation
Use business layer and data layer instead
Violation Code Sample
public partial class Form1 : Form // Form is in one of the namespaces for GUI
{
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection); // access to the DB => VIOLATION
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while (myReader.Read())
{
Console.WriteLine(myReader.GetString(0));
}
myReader.Close();
}
Related Technologies
.Net
Technical Criterion
Architecture - Multi-Layers and Data Access
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.