{"id":377,"date":"2015-01-27T11:10:55","date_gmt":"2015-01-27T11:10:55","guid":{"rendered":"http:\/\/adriangrigoras.com\/blog\/?p=377"},"modified":"2015-01-27T11:10:55","modified_gmt":"2015-01-27T11:10:55","slug":"data-access-layer-checklist","status":"publish","type":"post","link":"https:\/\/adriangrigoras.com\/blog\/data-access-layer-checklist\/","title":{"rendered":"Data Access Layer Checklist"},"content":{"rendered":"<h3>Design Considerations<\/h3>\n<ul>\n<li>Abstraction is used to implement a loosely coupled interface to the data access layer.<\/li>\n<li>Data access functionality is encapsulated within the data access layer.<\/li>\n<li>Application entities have been mapped to data source structures.<\/li>\n<li>Data exceptions that can be handled are caught and processed.<\/li>\n<li>Connection information is protected from unauthorized access.<\/li>\n<\/ul>\n<h3>Blob<\/h3>\n<ul>\n<li>Images are stored in a database only when it is not practical to store them on the disk.<\/li>\n<li>BLOBs are used to simplify synchronization of large binary objects between servers.<\/li>\n<li>Additional database fields are used to provide query support for BLOB data.<\/li>\n<li>BLOB data is cast to the appropriate type for manipulation within your business or presentation layer<\/li>\n<li>You did not store BLOB in the database when using buffered transmission.<\/li>\n<\/ul>\n<h3>Batching<\/h3>\n<ul>\n<li>Batched commands are used to reduce round trips to the database and minimize network traffic.<\/li>\n<li>Largely similar queries are batched for maximum benefit.<\/li>\n<li>Batched commands are used with a DataReader to load or copy multiple sets of data.<\/li>\n<li>Bulk copy utilities are used when loading large amounts of file-based data into the database.<\/li>\n<li>You did not place locks on long running batch commands.<\/li>\n<\/ul>\n<h3>Connections<\/h3>\n<ul>\n<li>Connections are opened as late as possible and closed as early as possible.<\/li>\n<li>Trusted sub-system authentication was used to maximize the effectiveness of connection pooling.<\/li>\n<li>Transactions are performed through a single connection where possible.<\/li>\n<li>Connection information is not stored in System or User Data Source Name (DSN) where possible.<\/li>\n<li>Retry logic was used to manage situations where the connection to data source is lost or times out.<\/li>\n<\/ul>\n<h3>Data Format<\/h3>\n<ul>\n<li>You have considered the use of custom data or business entities for improved application maintainability.<\/li>\n<li>You did not implement business rules in data structures associated with the data layer.<\/li>\n<li>XML was used when working with structured data that changes over time.<\/li>\n<li>DataSets have been considered for disconnected operations when dealing with small amounts of data.<\/li>\n<li>Serialization and interoperability requirements have been considered.<\/li>\n<\/ul>\n<h3>Exception Management<\/h3>\n<ul>\n<li>You have identified data access exceptions that should be handled in the data layer.<\/li>\n<li>Retry process for operations is implemented to handle data source errors or timeout errors.<\/li>\n<li>Appropriate exception propagation strategy is designed.<\/li>\n<li>Global exception handling has been implemented to catch unhandled exceptions.<\/li>\n<li>You have designed an appropriate logging and notification strategy for critical errors and exceptions.<\/li>\n<\/ul>\n<h3>Object Relational Mapping Considerations<\/h3>\n<ul>\n<li>Used or developed a framework to provides a layer between domain entities and the database.<\/li>\n<li>An O\/RM tool that will generate a schema to support the object model and provide a mapping between the database and domain entities is used in a Greenfield environment.<\/li>\n<li>Tools to map the domain model and relational model is used in a Brownfield environment.<\/li>\n<li>Data access pattern, such as Repository is used for smaller applications or when O\/RM tools are not available.<\/li>\n<\/ul>\n<h3>Queries<\/h3>\n<ul>\n<li>Parameterized SQL statements are used, instead of using literals, to reduce the chances of SQL Injection.<\/li>\n<li>User input has been validated when used with dynamically generated SQL queries.<\/li>\n<li>String concatenation has not been used to build dynamic queries in the data layer.<\/li>\n<li>Objects are used to build the database query.<\/li>\n<li>Business processing logic is not mixed with logic used to generate SQL statement when building dynamic SQL.<\/li>\n<\/ul>\n<h3>Stored Procedures<\/h3>\n<ul>\n<li>Output parameters are used to return single values.<\/li>\n<li>Individual parameters are used for single data inputs.<\/li>\n<li>XML parameters have been considered for passing lists or tabular data.<\/li>\n<li>Memory-based temporary tables are used only when required.<\/li>\n<li>Error handling has been implemented to return errors that can be handled by the application code.<\/li>\n<\/ul>\n<h3>Transactions<\/h3>\n<ul>\n<li>Transactions are enabled only when you need them.<\/li>\n<li>Transactions are kept as short as possible to minimize the amount of time that locks are held.<\/li>\n<li>Appropriate isolation level is chosen by doing a tradeoff between data consistency and contention.<\/li>\n<li>Manual or explicit transactions are used when performing transactions against a single database.<\/li>\n<li>You have considered the use of Multiple Active Result Sets (MARS) in transaction heavy concurrent applications to avoid potential deadlock issues.<\/li>\n<\/ul>\n<h3>Validation<\/h3>\n<ul>\n<li>All data received by the data layer is validated.<\/li>\n<li>User input used for dynamic SQL has been validated to prevent SQL injection attacks.<\/li>\n<li>All trust boundaries are identified, and data that crosses these boundaries is validated.<\/li>\n<li>You have determined whether validation that occurs in other layers is sufficient, or if you must validate it again.<\/li>\n<li>The data layer returns informative error messages if validation fails.<\/li>\n<\/ul>\n<h3>XML<\/h3>\n<ul>\n<li>XML readers and writers are used to access XML-formatted data.<\/li>\n<li>An XML schema was used to define formats for data stored and transmitted as XML.<\/li>\n<li>XML data is validated against the appropriate schemas.<\/li>\n<li>Custom validators are used for complex data parameters within your XML schema.<\/li>\n<li>XML indexes have been considered for read-heavy applications that use XML in SQL Server.<\/li>\n<\/ul>\n<h3>Manageability Considerations<\/h3>\n<ul>\n<li>A common interface or abstraction layer is used to provide an interface to the data layer.<\/li>\n<li>You have considered creating custom entities, or if other data representations better meet your requirements.<\/li>\n<li>Business or data entities are defined by deriving them from a base class that provides basic functionality and encapsulates common tasks.<\/li>\n<li>Business or data entities rely on data access logic components for database interaction.<\/li>\n<li>You have considered the use of stored procedures to abstract data access from the underlying data schema.<\/li>\n<\/ul>\n<h3>Performance Considerations<\/h3>\n<ul>\n<li>Connection pooling has been optimized based on performance testing.<\/li>\n<li>Isolation levels have been tuned for data queries.<\/li>\n<li>Commands are batched to reduce round-trips to the database server.<\/li>\n<li>Optimistic concurrency is used with non-volatile data to mitigate the cost of locking data in the database.<\/li>\n<li>Ordinal lookups are used for faster performance when using a DataReader.<\/li>\n<\/ul>\n<h3>Security Considerations<\/h3>\n<ul>\n<li>Windows authentication has been used instead of SQL authentication when using Microsoft SQL Server.<\/li>\n<li>Encrypted connection strings in configuration files are used rather than using a system or user DSN.<\/li>\n<li>Used a salted hash instead of an encrypted version of the password when storing passwords.<\/li>\n<li>Identity information is passed to the data layer for auditing purposes.<\/li>\n<li>Typed parameters are used with stored procedures and dynamic SQL to protect against SQL injection attacks.<\/li>\n<\/ul>\n<h3>Deployment Considerations<\/h3>\n<ul>\n<li>The data access layer is located on the same tier as the business layer to improve application performance.<\/li>\n<li>The TCP protocol has been used to improve performance when you need to support a remote data access layer.<\/li>\n<li>You did not locate the data access layer on the same server as the database.<\/li>\n<\/ul>\n<p>Source: apparch.codeplex.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Design Considerations Abstraction is used to implement a loosely coupled interface to the data access layer. Data access functionality is encapsulated within the data access layer. Application entities have been mapped to data source structures. Data exceptions that can be handled are caught and processed. Connection information is protected from unauthorized access. Blob Images are\u2026 <span class=\"read-more\"><a href=\"https:\/\/adriangrigoras.com\/blog\/data-access-layer-checklist\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-377","post","type-post","status-publish","format-standard","hentry","category-architecture"],"_links":{"self":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts\/377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/comments?post=377"}],"version-history":[{"count":1,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts\/377\/revisions"}],"predecessor-version":[{"id":378,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts\/377\/revisions\/378"}],"wp:attachment":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/media?parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/categories?post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/tags?post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}