LoadRunner executes the SQL statement action () {int numrows=0; int i=1; Establish database connection 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 "," Con Nectiontype=oledb ", last); Execute the SQL statement 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); Print out the results lr_db_dataset_action ("Stepname=printdataset", "Datasetname=mydataset", "Action=print", last);} The code above can run successfully, but what if you want to execute a multi-sentence statement? Continue thinking and want to perform the following declare @OperateID int = 2, @OperateTime date = getdate (), @SaleID intexec p_editsale @Flag = ' new_copy ', @Sale ID = @SaleID output, @CopySaleID = 1680, @IsCopyStyle = 1, @IsCopyShip = 1, @IsCopyBox = 1, @IsCopyScheme = 1, @IsCopyschemecolor = 1, @IsCopySchemeSize = 1, @IsCopyWork = 1, @OperateID = @OperateID, @OperateTime = @OperateTimeexec p_ed Itsale @Flag = ' save_new ', @SaleID = @SaleID, @OperateID = @OperateID, @OperateTime = @OperateTimeexec P_editsale @Flag = ' Clear ', @SaleID = @SaleID, @OperateID = @OperateID, @OperateTime = @OperateTime
LoadRunner connect to SQL database, get CAPTCHA script
1. Script protocol: Select Web Service2, Script: Action () {int numrows=0; Establish connection 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); Execute sqlnumrows = lr_db_executesqlstatement ("Stepname=performquery", "Connectionname=mecon",//Database statement "SQLStatement= SELECT TOP 1 sendcontent= SUBSTRING (Sendcontent,charindex (': ', sendcontent) +1,6) from si_sms ORDER by ID DESC "," Datasetna Me=mydataset ", last); Lr_output_message (" The query returned%d rows. ", NumRows); Print query Results/*lr_db_dataset_action ("Stepname=printdataset", "Datasetname=mydataset", "Action=print", last); *// Get SMS Content Lr_db_getvalue ("Stepname=getvalue", "Datasetname=mydataset", "Column=sendcontent", "Row=current", "OutParam= Myoutputparam ", last); Output Verification Code lr_output_message ("The value is:%d", lr_eval_string ("{Myoutputparam}")); Close link lr_db_disconnect ("Stepname=disconnect", "Connectionname=mecon", last); return 0;} 3. Output Result: (Code: 664545)
LoadRunner execute a clause SQL statement