首先需要安装 lr的.net add-in ,在开发环境编写代码,做数据库连接,然后调用执行存储过程。
装好以后,打开程序,应该看到菜单栏里多了一个:
然后添加一个lr项目:
之后就可以编码了,我写了个代码,如下:
using system;
using system.runtime.interopservices;
using system.componentmodel;
using system.data;
using system.data.oracleclient;
using shangxin.data;
using system.collections;
using system.web;
namespace loadrunneruser
{
/// <summary>
/// summary description for vuserclass.
/// </summary>
[classinterface(classinterfacetype.autodual)]
public class vuserclass
{
loadrunner.lrapi lr;
protected system.data.oracleclient.oracledataadapter oracleda;
protected system.data.oracleclient.oraclecommand loadcommand;
protected system.data.oracleclient.oracleconnection oracleconnection;
public vuserclass()
{
// loadrunner standard api interface :: do not remove!!!
lr = new loadrunner.lrapi();
}
protected system.data.oracleclient.oracleconnection getoracleconnection()////sqlconnection
{
if (oracleconnection==null)
oracleconnection=new system.data.oracleclient.oracleconnection();
oracleconnection.connectionstring="user id=test;password=write;data source=escalade";
return oracleconnection;
}
// ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int initialize()
{
// to do: add virtual user's initialization routines
return lr.pass;
}
// ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int actions()
{
try
{
lr.start_transaction("testgetwithdraworderbycode");
system.data.oracleclient.oracleconnection conn = new oracleconnection("user id=test;password=write;data source=escalade");
system.data.oracleclient.oraclecommand comm = new oraclecommand();
comm.connection = conn;
comm.commandtext = "bill.getwithdraworderbycode";
comm.commandtype = commandtype.storedprocedure;
//输入参数
system.data.oracleclient.oracleparameter param1=comm.parameters.add("v_code",oracletype.varchar,20);
param1.direction = parameterdirection.input;
param1.value ="th15";
//输出参数
system.data.oracleclient.oracleparameter param2=comm.parameters.add("retcursor",oracletype.cursor);
param2.direction = parameterdirection.output;
datatable dt = new datatable();
oracleda = new system.data.oracleclient.oracledataadapter();
oracleda.selectcommand = comm;
oracleda.fill(dt);
int icount=convert.toint32(dt.rows.count.tostring());
if(icount>0)
lr.end_transaction("testgetwithdraworderbycode",lr.pass);
else
lr.end_transaction("testgetwithdraworderbycode",lr.fail);
}
catch(exception ex)
{
string error = ex.message;
}
return lr.pass;
}
// ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int terminate()
{
// to do: add virtual user's termination routines
return lr.pass;
}
}
}
记得添加必要的引用,具体使用灵活掌握吧
新闻热点
疑难解答