Microsoft provides Data Access V2.0 in Microsoft Application Blocks for .NET with a large performance improvement than before, it can develop high performance and scalability .NET database application systems. But Data Access V2.0 is a versatile code, and it is necessary to adapt to the development of the actual application system.
When we do an application system, we use the structure of the DataAccess Dal MODEL PRES. The DataAccess is implemented by the SQL Server to execute the database stored procedure.
So, personalized demand can be generally defined as:
Uniform exposure to the static method of performing various storage procedures.
Connecting the string internalization and is not fixed during the call. (This is very important, the drawbacks set by each call are not stunned).
The connection string should be encrypted. Therefore, when reading, it is necessary to decrypt.
Can efficiently use the parameter cache support provided by Data Access V2.0.
Under these principles, we have improved the following Data Access, I hope the master doesn't finish your strength!
Unfortunately, there is no success since the code has been sent, all timeout :(
So I was sent to me in the blog of CNBLOGS, address:
http://www.cnblogs.com/wintle/archive/2004/08/09/31679.aspx
Interested to see :)
Here, I can only send the calling code, let's take a look:
Call DataAccess can be as follows:
Public Bool Create (String Name, String ShortName, INT32 UniversityID, String Code)
{
Sqlparameter [] PRAMS = {
Database.makeinparam ("@ name", system.data.sqldbtype.varchar, 60, name),
Database.makeinparam ("@ ShortName", System.Data.sqldbtype.varchar, 30, ShortName,
Database.makeinparam ("@ universityID", system.data.sqldbtype.int, 4, universityID,
Database.makeinparam ("@ code", system.data.sqldbtype.varchar, 30, code)
}
INT Reval = Database.Runproc ("BSCOLLE_CREATE", PRAMS;
IF (REVAL! = -1)
{
Return True;
}
Else
{
Return False;
}
}
If you need a cache support, use the following call method:
Public Void SelectSubnodes (int UniversityID, int Codelength, String code, Out OfficiateCollection List)
{
SqlDataReader Reader = NULL;
List = new officiatecollection ();
Sqlparameter [] PRAMS;
IF (Paramscache.getCached (Database.connectionstring, "BSofficiate_SelectSubnodes", Out Prams) {
Database.assignparameterValues (Prams, UniversityID, Codelength;
}
Else
{
Prams = new sqlparameter [3] {
Database.makeinparam ("@ universityID", system.data.sqldbtype.int, 4, universityID,
Database.makeinparam ("@ Codelength", System.Data.sqldbtype.int, 4, Codelength,
Database.makeinparam ("@ code", system.data.sqldbtype.varchar, 300, code)
}
Paramscache.cacheParameters (Database.connectionstring, "BSofficiate_selectsubnodes", PRAMS
}
Database.Runproc ("BSofficiate_SelectSubnodes", Prams, Out Reader;
While (Reader.Read ())
{
OFFICIATEINFO OFFICIATEINFO = New OFFICIATEINFO ();
OFFICIATEINFO.ID = int32.parse (Reader ["ID"]. TOSTRING ());
OFFICIATEINFO.NAME = Reader ["name"]. TOSTRING ();
OFFICIATEINFO.CODE = Reader ["Code"]. TOSTRING ();
OFFICIATEINFO.ordinal = int32.parse (Reader ["Ordinal"]. TOSTRING ());
List.add (OFFICIATEINFO);
}
Reader.Close ();
}
Based on this Data Access, our new CodePlus code generator automatically generates the above call code. For new version of CodePlus, you can find it here:
http://blog.9cbs.net/wintle/archive/2004/08/09/6881.aspx
For this DataAccess, if you have any good suggestions, please tell me, thank you.