时间:2021-07-01 10:21:17 帮助过:5人阅读
LoadRunner 执行单句SQL语句 Action() { int NumRows=0; int i=1; //建立数据库连接 lr_db_connect("StepName=DatabaseConnection", "ConnectionString=Provider=SQLOLEDB.1;Password=***;Persist Security Info=True;User ID=sc;Initial Catalog=EGMIS_NET;Data Source=192.168.0.3,7777", "ConnectionName=InvDatabaseConnection", "ConnectionType=OLEDB", LAST); //执行SQL语句 NumRows=lr_db_executeSQLStatement("StepName=PerformQuery", "ConnectionName=InvDatabaseConnection", "SQLStatement=SELECT * FROM T_Sale", "DatasetName=MyDataset", LAST); lr_output_message("The query returned %d rows.", NumRows); //打印出结果 lr_db_dataset_action("StepName=PrintDataset","DatasetName=MyDataset","Action=PRINT",LAST); } 上面的代码可以成功运行,但是如果想执行多句语句怎么办呢?继续思考,想执行如下的 declare @OperateID int = 2, @OperateTime date = getdate(), @SaleID int exec P_EditSale @Flag = ‘New_Copy‘, @SaleID = @SaleID output, @CopySaleID = 1680, @IsCopyStyle = 1, @IsCopyShip = 1, @IsCopyBox = 1, @IsCopyScheme = 1, @IsCopySchemeColor = 1, @IsCopySchemeSize = 1, @IsCopyWork = 1, @OperateID = @OperateID, @OperateTime = @OperateTime exec P_EditSale @Flag = ‘Save_New‘, @SaleID = @SaleID, @OperateID = @OperateID, @OperateTime = @OperateTime exec P_EditSale @Flag = ‘Clear‘, @SaleID = @SaleID, @OperateID = @OperateID, @OperateTime = @OperateTime
Loadrunner连接SQL数据库,获取验证码脚本
1、脚本协议:选择web service 2、脚本: Action() { int NumRows=0; //建立连接 lr_db_connect("StepName=DatabaseConnection", "ConnectionString=Data Source=192.168.1.251;Initial Catalog=MY_test;Persist Security Info=True;User ID=sa;Password=test1", "ConnectionName=MeCon", "ConnectionType=SQL", LAST ); //执行SQL NumRows = lr_db_executeSQLStatement("StepName=PerformQuery", "ConnectionName=MeCon", // 数据库语句 "SQLStatement=SELECT TOP 1 SendContent= SUBSTRING(SendContent,CHARINDEX(‘:‘,SendContent)+1,6) FROM si_sms ORDER BY id DESC ", "DatasetName=MyDataset", LAST ); lr_output_message("The query returned %d rows.", NumRows); //打印查询结果 /* lr_db_dataset_action("StepName=PrintDataset", "DatasetName=MyDataset", "Action=PRINT", LAST );*/ //获取短信内容 lr_db_getvalue("StepName=GetValue", "DatasetName=MyDataset", "Column=SendContent", "Row=current", "OutParam=MyOutputParam", LAST ); // 输出验证码 lr_output_message("The value is: %d", lr_eval_string("{MyOutputParam}") ); //关闭链接 lr_db_disconnect("stepname=Disconnect","connectionname=MeCon",LAST); return 0; } 3、输出结果:(验证码:664545)
LoadRunner 执行单句SQL语句
标签: