Loadrunner connects to the SQL database, obtains the verification code script, and loadrunnersql
1. Script protocol:Select web service
2. Script:
Action ()
{
Int NumRows = 0;
// Establish a connection
Lr_db_connect ("StepName = DatabaseConnection ",
"ConnectionString = Data Source = 192.168.1.20.; Initial Catalog = MY_test; Persist Security Info = True; User ID = sa; Password = test1 ",
"ConnectionName = MeCon ",
"ConnectionType = SQL ",
LAST );
// Execute SQL
NumRows = lr_db_executeSQLStatement ("StepName = descrimquery ",
"ConnectionName = MeCon ",
// Database statement
"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 );
// Print the query result
/*
Lr_db_dataset_action ("StepName = PrintDataset ",
"DatasetName = MyDataset ",
"Action = PRINT ",
LAST );*/
// Obtain the text message content
Lr_db_getvalue ("StepName = GetValue ",
"DatasetName = MyDataset ",
"Column = SendContent ",
"Row = current ",
"OutParam = MyOutputParam ",
LAST );
// Output the verification code
Lr_output_message ("The value is: % d", lr_eval_string ("{MyOutputParam }"));
// Close the link
Lr_db_disconnect ("stepname = Disconnect", "connectionname = MeCon", LAST );
Return 0;
}
3. output results(Verification Code: 664545)