How to perform MSSQL load testing in JMeter?

In this article we are going to see how to perform Load / Stress test for MS SQL Server. It is applicable for SQL 2008, 2005, SQL Express.

For Basic Idea on jmeter, See my this post.

Step : 1 
To Test Database, we have to access the database directly as jmeter does not send request via browser. So,we need a driver or communication way to access DB. As Jmeter is build on JAVA, so we have to use JDBC driver. JDBC driver is different for different Database Server. As we are focused on MS SQL in this post, we will be needing a JDBC driver.
I am using MS SQL Server jdbc driver 4.0. Download the from here(download). 
[Note : Use sqljdbc4.jar . sqljdbc.jar is for old java versions]

Step : 2
-After download driver , Unzip and we will get sqljdbc4.jar we have to copy this to \apache-jmeter-2.8\lib (Library Directory)
 

Step : 3 
- Run Jmeter

Step : 4 
-Add a Thread Group to default test plan(I use 2 user, 1 second, 2 iteration)

Step : 6 
-Add a JDBC Connection Configuration under thread group( it is one kind of Config Element)
[This will control the settings to communicate with database]

Step : 7 
-Provide a Variable Name
Note : Every Variable name represents a configuration settings, so if we add more JDBC Connection Configuration, each one should identically differently from other by variable names. I use SQL Authentication,
Database Connection Configuration :  
Database URL: jdbc:sqlserver://[server address];databaseName=[DataBase Name]
JDBC Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver
Username: (Ex-shantonu)
Password: (Ex-p@ssw0rD)
You can find the syntax details here

Step : 8 
-Add JDBC Request( it is one kind of Sampler) under the thread group. [This sends the query, procedure on DB]

Step : 9 
- Provide Variable Name as the mane from JDBC Connection Configuration. This name should be same as any one of JDBC Connection Configuration that is present in the test plan.

So,
-We have to add sql query in SQL Section. This is the the test query that will be using for load in the Database. I have tasted
1. Local SQLEXPRESS : "Select count(*) from t_TestTable"
2. Remote Server : Select COUNT(*) from Configurations







My sample Database Structure :
- Select the type of Query




Note : We can also use Sourceforge provide a JDBC driver (JTDL for MSSQL Server) link. 
In that Case :
Database URL jdbc:jtds:sqlserver:// [server name or ip] / [db name]]
JDBC Driver Class: net.sourceforge.jtds.jdbc.Driver
Username: (Ex-shantonu)
Password: (Ex-p@ssw0rD)

Note :
-If you use SQLExpress don't miss the followings a: Active SQL Express Service, b: Active  SQL Express Browsing Service, c: Active  SQL Express Browsing enabled from TCP/IP ( Use SQL Server Configuration Manager)
-It is better to Use SQL Authentication (so, know your sa password. This link might help)
-If you do not use SQL Authentication the Database URL : jdbc:sqlserver://[server address];instanceName=[name];databaseName=[dbName]

-Add listeners, You can add any kind of listeners, I have used only View Results in tree.

Now, Run the Test and monitor the data.

...Thanks....:)