The original idea is to try to record in the SQL Server2008 operation, but even if they do not record the query SQL statement, the online search data is all about SQL 2000 (this part of the experience of welcome advice).
Therefore, the performance test of SQL statements can only be achieved by invoking the function of LoadRunner itself directly. The main use is lr_db_connect and lr_db_executesqlstatement two functions, the specific usage here does not explain, please check the LoadRunner help instructions.
Let's get down to the chase. In the help description of the function Lr_db_connect, there is the phrase "important:this function is available only from within Web Services scripts." This sentence determines that we can only select the Web Services protocol when the agreement is selected. A script is attached below
1 Action ()2 {3 intNumrows=0;4 Doubletimes=0;5 intI=1;6Lr_db_connect ("Stepname=connect", 7 "Connectionstring=provider=sqloledb;data Source=.;i Nitial catalog=loadrunner_test; User Id=sa; password= Password",8 "CONNECTIONNAME=DB1",9 "Connectiontype=oledb",//connectiontype= sql,ConnectionString is not available with Provider; =OLE DB , must be with Provider Ten Last ); One A - -Lr_start_transaction ("SQL query" ); theNumrows=lr_db_executesqlstatement ("Stepname=query", - "CONNECTIONNAME=DB1", - "Sqlstatement=select * from Dbo.test_table", - "Datasetname=mydataset", + Last ); -Times=lr_get_transaction_duration ("SQL query"); +Lr_end_transaction ("SQL query", Lr_auto); A at - - while(i<=Ten) { -Lr_db_getvalue ("Stepname=getvalue", - "Datasetname=mydataset", - "Column=username", in "Row=next", - "Outparam=myoutputparam", to Last ); +Lr_output_message ("The value is:%s", Lr_eval_string ("{Myoutputparam}") ); -i=i+1; the } *Lr_output_message ("The query returned%d rows.", NumRows); $Lr_output_message ("SQL statement execution time%f", times);Panax Notoginseng return 0; -}
For the above script, it is difficult to place the following several aspects:
1,ConnectionString: Really so many versions of SQL, help gave a connectiontype for SQL example, can not say pit dad. Attached below is a connection that contains the data source
: http://www.connectionstrings.com/
2,connectiontype=oledb connectionstring must be specified after the Provider property,Connectiontype=sql and absolutely not to specify Provider attribute, I really want to talk dirty.
The connectionname in 3,lr_db_connect can be arbitrarily specified, but the connectionname in Lr_db_executesqlstatement Must be consistent with it
LoadRunner Test SQL statement Performance