Enterprise Library Data Access Application Block + SQL Optional Parameters
The Enterprise Library Data Access Block provides a number of ways of calling a stored procedure.
Database _db = DatabaseFactory.CreateDatabase(<Connection String Name>);
Let's now assume that we have a stored procedure usp_MyStoredProc that takes a single parameter @param1. If this is a require parameter, both of the following statement blocks will result in the same outcome:
public DataSet CallMyStoredProc( int value ){
return _db.ExecuteDataSet( "usp_MyStoredProc", value )
}
public DataSet CallMyStoredProc( int value ){
DbCommand command = _db.GetStoredProcCommand("usp_MyStoredProc" );
_db.AddInParameter( command, "param1", value );
return _db.ExecuteDataSet( command );
}
However, now let's assume that @param1 is an optional parameter that we don't want to pass in from our data access method, we are limited in our options.
public DataSet CallMyStoredProc(){
return _db.ExecuteDataSet( "usp_MyStoredProc")
}
This method will fail with an exception because the parameters provided to the stored procedure (none) don't match the parameter count for the stored procedure (1).
Creating an actual DbCommand and executing it, however, will not cause an exception. In this scenario, the following code block will work without causing an exception:
public DataSet CallMyStoredProc( int value ){
DbCommand command = _db.GetStoredProcCommand("usp_MyStoredProc" );
return _db.ExecuteDataSet( command );
}
Performance and Load Testing with WebLoad
Recently, I had to perform a load test on our new project. We are using WebLoad to test the performance at different levels of load to see how it holds up. While WebLoad offers its own set of analytics, I am also using perfmon to see how each tier is performing under the stress.
I originally planned on using WebLoad 8.4 for the performance testing but have decided to stick with version 8.1. The free license for 8.4 limits you to 10 virtual users (the load size) where as V8.1 does not have any limitation.
WebLoad 8.1 can be downloaded here.
Perfmon Counters
The following counters will give the most pertinent results.
ASP.NET
- Requests Queued
- Requests Current
- Request Execution Time (lower is better)
- Request Wait Time (lower is better)
- Requests Rejected (lower is better, is best)
System
- Context Switches / sec
Memory
- Pages / sec
- Available Bytes
- Committed Bytes
Processor
- % Processor Time
- Active Server Pages
- Request Wait Time
- Requests Queued
Web Service
- Current Connections
- Bytes Send / sec
- Connection Attempts / sec
- Current Blocked Async I/O Requests
- Current Blocked bandwidth bytes