1. SPEForums need your contributions to build up a strong repository of performance engineering resources.

    Dismiss Notice
  2. Whatsapp Group For Software Performance Engineering Professionals!! Click here to get added . No Spam for strictly professional discussions only.
    Dismiss Notice
Dismiss Notice
Hello Guest,

Please reach out to us at admin@speforums.com/+91 8600177662 in case you face any issues with SPEForums. Share your feedback - Click Here

Please support us by sharing performance engineering tutorials/resources with SPEForums.com

-Crew

Database Test Plan using Loadrunner Web - HTTP/HTML protocol

Create a simple database test plan using loadrunner tool

  1. AnmolD
    Objective : In this tutorial we would connect to mysql database in loadrunner and insert a row in sample database. We would be connecting to database using web protocol.

    Pre-Requisite :
    1. Prepare a database in mysql similar to this tutorial - http://www.speforums.com/resources/database-test-plan-using-jmeter-for-stored-procedure-testing.8/
    2. Copy libmysql.dll from mysql installation to your loadrunner lib directory
    Note - For creating similer test plan in JMeter see this tutorial - http://www.speforums.com/resources/database-test-plan-using-jmeter-for-stored-procedure-testing.8/

    Sample Script:

    Create a test script in web- HTTP/HTML protocol in Load runner.
    Using below script you can talk to mysql database and insert a row in the sample database table

    ===================

    // The MySQL 5.0 C API documentation is available from:
    // http://dev.mysql.com/doc/refman/5.0/en/c-api-functions.html

    // Note that this code may have problems with thread safety.
    // It is therefore best to run each vuser as a process rather than as a thread.

    Action()
    {
    int rc; // return code
    int db_connection; // Declaractions is a bit dodgy. Should really use MYSQL defined in mysql.h
    int query_result; // Declaractions is a bit dodgy. Should really use MYSQL_RES defined in mysql.h
    char** result_row; // Return data as array of strings. Declaractions is a bit dodgy. Should really use MYSQL_ROW defined in mysql.h

    char *server = "localhost";
    char *user = "root";
    char *password = ""; // very naughty to leave default root account with no password :)
    char *database = "testing";
    int port = 3306; // default MySQL port
    int unix_socket = NULL; // leave this as null
    int flags = 0; // no flags

    // You should be able to find the MySQL DLL somewhere in your MySQL install directory.
    rc = lr_load_dll("C:\\Program Files (x86)\\HP\\LoadRunner\\Lib\\libmysql.dll");
    if (rc != 0) {
    lr_error_message("Could not load libmysql.dll");
    lr_abort();
    }

    // Allocate and initialise a new MySQL object
    db_connection = mysql_init(NULL);
    if (db_connection == NULL) {
    lr_error_message("Insufficient memory");
    lr_abort();
    }

    // Connect to the database
    rc = mysql_real_connect(db_connection, server, user, password, database, port, unix_socket, flags);
    if (rc == NULL) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
    }

    // INSERT a row into the database table
    lr_param_sprintf("paramInsertQuery", "INSERT INTO test (LastName, FirstName) VALUES ('testLN4', 'testFN4');"); // use current time as order ID for this example
    rc = mysql_query(db_connection, lr_eval_string("{paramInsertQuery}"));
    if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
    }
    else
    {
    lr_outpput_message("Insert Successful");
    }


    // Free the MySQL object created by mysql_init
    mysql_close(db_connection);

    return 0;
    }

Recent Reviews

  1. amitbose
    amitbose
    5/5,
    Great Article - was looking for this