using System.Runtime.InteropServices;
using System.Data.OleDb;
using System.Data;
{
/// <summary>
/// Summary description for VuserClass.
/// </summary>
[ClassInterface(ClassInterfaceType.AutoDual)]
public class VuserClass
{
LoadRunner.LrApi lr;
{
// LoadRunner Standard API Interface :: DO NOT REMOVE!!!
lr = new LoadRunner.LrApi();
}
public int Initialize()
{
// TO DO: Add virtual user's initialization routines
lr.message("Initialize部分,我只执行一次哦!");
return lr.PASS;
}
public int Actions()
{
// TO DO: Add virtual user's business process actions
lr.message("Actions部分,我可以重复执行(在设置迭代情况下)!");
try
{
//设置连接字符串开始
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;";
strConnection+=@"Data Source=C:\\test.mdb";
//设置连接字符串结束
lr.rendezvous("集合点");
//插入一个集合点结束
lr.start_transaction("SQL语句性能");
System.Data.OleDb.OleDbConnection conn=new
System.Data.OleDb.OleDbConnection(strConnection);
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from testdb";
//建立OleDbConnection和OleDbCommand,并指定要运行的Sql语句结束
lr.log_message("LOG: Sql语句开始执行了,Sql="+cmd.CommandText);
//插入一个日志结束
DataTable dt = new DataTable();
System.Data.OleDb.OleDbDataAdapter oleDA = new
System.Data.OleDb.OleDbDataAdapter();
oleDA.SelectCommand = cmd;
oleDA.Fill(dt);
//将查询结果填充到DataTable结束
lr.log_message("LOG: Sql语句执行完成,Sql="+cmd.CommandText);
//插入一个日志结束
int iCountRec=Convert.ToInt32(dt.Rows.Count.ToString());
conn.Close();//关闭连接
//如果记录数大于0,完整这个事务,否则标识事务失败
if(iCountRec>0)
lr.end_transaction("SQL语句性能",lr.PASS);
else
lr.end_transaction("SQL语句性能",lr.FAIL);
lr.output_message("Welcome "+lr.eval_string("<username>")+"!");
lr.think_time(3);
}
{
conn.Close();//关闭连接
string error = ex.Message;
}
}
public int Terminate()
{
// TO DO: Add virtual user's termination routines
lr.message("Terminate部分,我只执行一次哦!");
return lr.PASS;
}
}