LoadRunner using ODBC to write MySQL scripts

Source: Internet
Author: User
Tags odbc mysql odbc driver


The LoadRunner Test database is a simulated client to connect to the database server, and therefore requires protocol (or driver support). The loadrunner itself directly supports Oracle, SQL Server databases, which can record scripts directly from the two databases by selecting the appropriate protocol. The MySQL database can only use the ODBC Protocol to record (write) the script, so you have to MySQL ODBC driver, and ODBC-enabled Query Analyzer (recording scripts need to write their own do not need).

1, first to install the MySQL ODBC driver, MyODBC 3.51.11 WIN.

2. Open "Data source ODBC" from "Control Panel" if not found (not found on my computer). To the desktop, create a new shortcut to the target location:%systemroot%\system32\odbcad32.exe.

3, open the ODBC management program, add the driver for "MySQL ODBC 3.51 Driver", and then fill in some IP, user name, password and so on, test it. (This step is not necessary, if you write a connection string, you do not need, if you want to use the DNS database name, it is necessary)

4, install a Query Analyzer, this Query Analyzer must be supported by ODBC (this is necessary, otherwise not recorded), this is very difficult to find. I looked for one, not good enough, called "Universal Database Query Analyzer." Http://www.onlinedown.net/soft/31366.htm.

5, Start loadrunner,create scripts;application type select Win32 applications;program record Select the 4th step of the Query Analyzer location, remember the Query Analyzer select "ODBC", Before you can record it, it's OK to run it.

6, Run Load tests, if the failure, see if license support, with GLOBAL-100 license on it.

The recorded script was miserable (and smelly and long), so I tried to manually write a simple one, each line has comments, if you want to advanced, please refer to LoadRunner's help documentation.

View Plaincopy to Clipboardprint?

#include"lrd.h"Action () {StaticLrd_init_info Initinfo ={Lrd_init_info_eyecat}; StaticLrd_default_db_version dbtypeversion[] ={{lrd_dbtype_odbc, lrd_dbversion_odbc_30}, {Lrd_dbtype_none, lrd_dbversion_none}}; StaticLrd_context FAR *Ctx1; StaticLrd_connection FAR *Con1; StaticLrd_cursor FAR *CSR1; //The above defined code is defined in Vdf.h if the script is recorded , and there are some other files//If you have a handwritten script, you need to add it manually, mostly by defining variables//number of rows queriedUnsignedLongCount=0; //InitialLrd_init (&Initinfo, dbtypeversion); //Open ContextLrd_open_context (&CTX1, LRD_DBTYPE_ODBC,0,0,0); //request a connected memoryLrd_alloc_connection (&con1, LRD_DBTYPE_ODBC, CTX1,0 /*Unused*/,0); //Open the connection, note that the driver is installed aboveLrd_open_connection (&con1, LRD_DBTYPE_ODBC,"","","","driver=mysql ODBC 3.51 DRIVER; Uid=root; pwd=123456; Server=192.168.1.99;database=testdb", CTX1,1,0); //Open CursorLrd_open_cursor (&CSR1, Con1,0); //SQL statement, note that 1 means to execute immediatelyLrd_stmt (CSR1,"Select Column1 from table1 where colum1 = 1", -1,1,0 /*None*/,0); //counting rows to the count variableLrd_row_count (CSR1, &count,0); //Print MessagesLr_message ("count=%d", Count); //close the cursor firstLrd_close_cursor (&CSR1,0); //Close the connection againLrd_close_connection (&con1,0,0); //release the connection, and echo the alloc, otherwise there is a memory leakLrd_free_connection (&con1,0 /*Unused*/,0); //Close the context againLrd_close_context (&CTX1,0,0); //finished, return 0return 0; } #include"lrd.h"Action () {StaticLrd_init_info Initinfo ={lrd_init_info_eyecat};StaticLrd_default_db_version dbtypeversion[] ={{lrd_dbtype_odbc, lrd_dbversion_odbc_30}, {Lrd_dbtype_none, Lrd_dbversion_none}};StaticLrd_context FAR *Ctx1;StaticLrd_connection FAR *Con1;StaticLrd_cursor FAR *CSR1;//The above defined code is defined in Vdf.h if the script is recorded , and there are some other files//If you have a handwritten script, you need to add it manually, mostly by defining variables//number of rows queriedUnsignedLongCount=0;//InitialLrd_init (&Initinfo, dbtypeversion);//Open ContextLrd_open_context (&CTX1, LRD_DBTYPE_ODBC,0,0,0);//request a connected memoryLrd_alloc_connection (&con1, LRD_DBTYPE_ODBC, CTX1,0 /*Unused*/,0);//Open the connection, note that the driver is installed aboveLrd_open_connection (&con1, LRD_DBTYPE_ODBC,"","","","driver=mysql ODBC 3.51 DRIVER; Uid=root; pwd=123456; Server=192.168.1.99;database=testdb", CTX1,1,0);//Open CursorLrd_open_cursor (&CSR1, Con1,0); //SQL statement, note that 1 means to execute immediatelyLrd_stmt (CSR1,"Select Column1 from table1 where colum1 = 1", -1,1,0 /*None*/,0);//counting rows to the count variableLrd_row_count (CSR1, &count,0);//Print MessagesLr_message ("count=%d", count);//close the cursor firstLrd_close_cursor (&CSR1,0);//Close the connection againLrd_close_connection (&con1,0,0);//release the connection, and echo the alloc, otherwise there is a memory leakLrd_free_connection (&con1,0 /*Unused*/,0);//Close the context againLrd_close_context (&CTX1,0,0);//finished, return 0return 0;}

Finish it, run it yourself. You can view the log as follows:

------------------------------------------------------------------------------

Starting Iteration 1.
Starting action action.
ACTION.C (8): lrd_open_connection:user= "", server= ""
ACTION.C (one): Lrd_stmt:select column1 from table1 where colum1 = 1;
Count= 1
ACTION.C (+): lrd_close_connection:user= "", server= ""
Ending action action.

------------------------------------------------------------------------------

Count = 1 indicates that the query succeeded

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

LoadRunner using ODBC to write MySQL scripts (go)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.