DALC4NET (All in One Data Access Layer for .NET)

No.of Views882
Bookmarked0 times
Downloads 
Votes0
By  ak.tripathi@yahoo.com   On  07 Feb 2011 20:02:11
Tag : .NET Frameworks , Utilities
DALC4NET is an Open Source data access layer for Microsoft.NET projects. This enables users to connect any kind of database (SQL Server/ Oracle/ My Sql/ MS Access/ MS Excel etc) in optimal fashion. Ability to connect to MySql database using MySql Connector for .NET is the key feature of the DALC4NET. In fact various data access layer components available mainly connects to Sql Server/ Oracle etc.. but not MySql Database using the connector provided by MySql.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

DALC4NET is an Open Source data access layer built for Microsoft .NET projects.  This enables us accessing data from SQL Server, Oracle, MySql, MS Access, MS Excel etc data bases.
DALC4NET is developed using C#.NET.  Microsoft .NET Framework 2.0 is required to use DALC4NET.Users are free modify the source code as per their need.


For any feedback/ suggestion you can mail the author at ak.tripathi@yahoo.com with subject line ‘DALC4NET’

Note: In order to connect with MySql database you need to have MySql connector for .NET. Which may be downloaded from the below url
http://dev.mysql.com/downloads/connector/net/

Various Providers 

Image Loading

How to use DALC4NET?

1.    Download DALC4NET.dll from http://www.codegain.com/dalc4net/
2.    Add reference of the DALC4NET.dll to your project
3.    Import the namespace DALC4NET (e.g. using DALC4NET;)
4.    Create instance of DBHelper class of DALC4NET library. This class facilitate us for execution of any kind of SQL Command or stored procedure.

DBHelper.cs is a singleton class and hence we will not see any constructor for DBHelper class (singleton class has private contructor). GetInstance() method can be used for creating the instance of the class. GetInstance() method has three overloads.

i.    No Parameter

 

Image Loading

This instance does not require any parameter. This overload creates connection for the connection string name mentions as the default connection.

Image Loading

Note: For using this overload ad an appSettings key “defaultConnection” and set you appropriate connection’s name as the value for this key.  This is the most recommended overload as we need not to do any kind of code changes if we want switch over the database. E.g. Application is supposed to have three databases MS SQL Server, Oracle and MySql. Create three Connection strings into app/web.config file’s connectionString’s section say sqlCon, oracleCon, mySqlCon. If you want application to use SQL Server set value=”sqlCon” for the appSetting’s key=” defaultConnection”. In future if your client want to use oracle database then after porting the oracle database you simply need to change the defaultConnection value i.e. value = “oracleCon”

ii.    Connection Name as a parameter 

Image Loading

This overload creates instance for the connection name specified into app/web.config file.
iii.    Connection String and Provider Name as parameters 

Image Loading

This overload creates instance for the specified connection string and provider name.

How Execute SQL Command/ Stored Procedures

In section 2 we created instance of the DBHelper class say _dbHelper. We can execute any Sql Command as follows
4.1    Execute SQL Command

string sqlCommand = "SELECT Count(1) FROM USERDETAILS";
object objCont = _dbHelper.ExecuteScalar(sqlCommand);

4.2    Execute Stored Procedure with parameters

object objCont = _dbHelper.ExecuteScalar("PROC_DALC4NET_EXECUTE_SCALAR_SINGLE_PARAM", new DBParameter("@FIRSTNAME", "ashish"), CommandType.StoredProcedure);

In the similar way we may use the appropriate method and overload to execute Sql Command or stored procedure.

DALC4NET Design Overview

Image Loading

DALC4NET is implements following design patterns Singleton, Provider and Factory design pattern.
DALC4NET has only three public classes i.e. DBHelper, DBParameter and DBParameterCollection 

Image Loading

Singleton Design Pattern Implementation

DBHelper class

DBHelper is a singleton class and it has three private constructors. Appropriate constructor is called on invoking the static method GetInstance. This method first of all checks if there is any live instance of the class then that instance is returned. If instance is null (i.e. no live instance) then a new instance is created using appropriate constructor.

private static DBHelper _dbHelper = null;
public static DBHelper GetInstance()
      	{
            	if (_dbHelper == null)
                		_dbHelper = new DBHelper();

            return _dbHelper;
        	}

AssemblyProvider class

AssemblyProvider class also is implemented as singleton as this is the class responsible for loading the appropriate assembly for the specified provider. If this class is not implemented as singleton then every time when this class is instantiated assembly is loaded, this may be costly operation for memory.
Singleton implementation is similar as above.

Download Sample Projects 

Download DALC4NET Dll -7 kb

Download source files -50 kb

Summary

DALC4NET is an Open Source data access layer for Microsoft.NET projects. This enables users to connect any kind of database (SQL Server/ Oracle/ My Sql/ MS Access/ MS Excel etc) in optimal fashion.Ability to connect to MySql database using MySql Connector for .NET is the key feature of the DALC4NET. In fact various data access layer components available mainly connects to Sql Server/ Oracle etc.. but not MySql Database using the connector provided by MySql.

 
Sign Up to vote for this article
 
About Author
 
ak.tripathi@yahoo.com
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-27 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
    Let us start this article by a small chat between customer and developer. Scenario 1 Customer: - How’s your application performance? Subjective developer: - Well it’s speedy, it’s the best …huuh aaa ooh it’s a like rocket. Scenario 2 Customer: - How’s your application performance? Quantitative developer: - With 2 GB RAM , xyz processor and 20000 customer records the customer screen load in 20 secs. I am sure the second developer looks more promising than the first developer. In this
    Published Date : 10/May/2010
    Ask any developer which is the best place in a .NET class to clean unmanaged resources?, 70% of them will say the destructor. Although it looks the most promising place for cleanup it has a huge impact on performance and memory consumption. Writing clean up code in the destructor leads to double GC visits and thus affecting the performance multifold times. In order to validate the same we will first start with bit of theory and then we will actually see how GC algorithm performance is impacte
    Published Date : 06/May/2010
    One of the important factors for performance degradation in .NET code is memory consumption. Many developers just concentrate on execution time to determine performance bottle necks in a .NET.
    Published Date : 05/May/2010
    This article will explain 6 important concepts Stack , heap , by val , by ref , boxing and unboxing. This article starts first explaining what happens internally when you declare a variable and then i
    Published Date : 02/May/2010
    Introduction Value Types in .Net Framework
    Published Date : 09/Apr/2010
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top