黑喵村长 发表于 2016-12-6 15:12:17

loadrunner如何实时获取数据库里的数据?

数据库 里的数据是不断更新的,那么lr在压测的时候,能实时获取数据库 里的数据吗?
通过关联操作,能解决这一问题吗?

104~牛牛 发表于 2016-12-7 11:20:56

下面以oracle数据库为例:
Action()
{
intNumRows=0;
inti=1;

//建立数据库连接
lr_db_connect("StepName=DatabaseConnection",
"ConnectionString=Provider=OraOLEDB.Oracle.1;Password = test ;Persist Security Info=True; User ID= test ; Data Source = betadb ; Server = 172.19.188.191",
"ConnectionName=InvDatabaseConnection",
"ConnectionType=OLEDB",
LAST);

//执行SQL语句
NumRows=lr_db_executeSQLStatement("StepName=PerformQuery",
"ConnectionName=InvDatabaseConnection",
"SQLStatement=SELECT cons_no,cons_id FROM c_cons where rownum<10",
"DatasetName=MyDataset",
LAST);
lr_output_message("The query returned %d rows.", NumRows);

//打印出结果
lr_db_dataset_action("StepName=PrintDataset",
"DatasetName=MyDataset",
"Action=PRINT",
LAST);


//利用循环检索数据值
while(i<10) {
lr_db_getvalue("StepName=GetValue",
"DatasetName=MyDataset",
"Column=CONS_NO",
"Row=next",
"OutParam=MyOutputParam",
LAST);
lr_output_message("The value is: %s", lr_eval_string("{MyOutputParam}") );
i=i+1; }


//释放结果
lr_db_dataset_action("StepName=RemoveDataset",
"DatasetName=MyDataset",
"Action=REMOVE",
LAST);


//断开数据库连接
lr_db_disconnect("StepName=Disconnect",
"ConnectionName=InvDatabaseConnection",
LAST);

return0;
}

jingzizx 发表于 2016-12-16 18:11:41

很详细啊
页: [1]
查看完整版本: loadrunner如何实时获取数据库里的数据?