LoadRunner using ODBC to write MySQL scripts

Source: Internet
Author: User
Tags mysql odbc driver

Category: 4. Software Design/Architecture/testing 2010-01-08 17:48 5635 people read reviews (3) favorite reports Loadrunnermysql script Database SQL Server Test

Recently did a few weeks of loadrunner test, have some experience, recorded, in order to find later.


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.

[CPP]View Plaincopy
  1. #include "Lrd.h"
  2. Action ()
  3. {
  4. Static Lrd_init_info Initinfo = {Lrd_init_info_eyecat};
  5. Static lrd_default_db_version dbtypeversion[] =
  6. {
  7. {LRD_DBTYPE_ODBC, lrd_dbversion_odbc_30},
  8. {Lrd_dbtype_none, Lrd_dbversion_none}
  9. };
  10. Static Lrd_context FAR * CTX1;
  11. Static lrd_connection FAR * CON1;
  12. Static Lrd_cursor FAR * CSR1;
  13. The above defined code is defined in Vdf.h if the script is recorded, and there are some other files
  14. If you have a handwritten script, you need to add it manually, mostly by defining variables
  15. Number of rows queried
  16. unsigned long count=0;
  17. Initial
  18. Lrd_init (&initinfo, dbtypeversion);
  19. Open context
  20. Lrd_open_context (&ctx1, LRD_DBTYPE_ODBC, 0, 0, 0);
  21. Request a connected memory
  22. Lrd_alloc_connection (&con1, Lrd_dbtype_odbc, Ctx1, 0 /*unused*/, 0);
  23. Open the connection, note that the driver is installed above
  24. Lrd_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);
  25. Open cursor
  26. Lrd_open_cursor (&CSR1, Con1, 0);
  27. SQL statement, note that 1 means to execute immediately
  28. Lrd_stmt (CSR1, "select Column1 from table1 where colum1 = 1",-1, 1, 0 /*none*/, 0);
  29. Counting rows to the count variable
  30. Lrd_row_count (CSR1, &count, 0);
  31. Print messages
  32. Lr_message ("count=%d", count);
  33. Close the cursor first
  34. Lrd_close_cursor (&CSR1, 0);
  35. Close the connection again
  36. Lrd_close_connection (&con1, 0, 0);
  37. Release the connection, and echo the alloc, otherwise there is a memory leak
  38. Lrd_free_connection (&con1, 0 /*unused*/, 0);
  39. Close the context again
  40. Lrd_close_context (&ctx1, 0, 0);
  41. Finished, return 0
  42. return 0;
  43. }

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

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.