利用loadrunner測試ORACLE預存程序的效能

來源:互聯網
上載者:User

  首先需要安裝 LR的.NET ADD-IN ,在開發環境編寫代碼,做資料庫連接,然後調用執行預存程序。

  裝好以後,開啟程式,應該看到功能表列裡多了一個:

  然後添加一個LR項目:

  之後就可以編碼了,我寫了個代碼,如下:

using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using ShangXin.Data;
using System.Collections;
using System.Web;
  namespace LoadRunnerUser
{
/// <summary>
/// Summary description for VuserClass.
/// </summary>
[ClassInterface(ClassInterfaceType.AutoDual)]
public class VuserClass
{
LoadRunner.LrApi lr;
protected System.Data.OracleClient.OracleDataAdapter oracleDA;
protected System.Data.OracleClient.OracleCommand loadCommand;
protected System.Data.OracleClient.OracleConnection oracleConnection;
  
public VuserClass()
{
// LoadRunner Standard API Interface :: DO NOT REMOVE!!!
lr = new LoadRunner.LrApi();
}
  protected System.Data.OracleClient.OracleConnection GetOracleConnection()////sqlConnection
{
if (oracleConnection==null)
oracleConnection=new System.Data.OracleClient.OracleConnection();
oracleConnection.ConnectionString="User Id=test;Password=write;Data Source=escalade";
return oracleConnection;
}
  
// ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int Initialize()
{
// TO DO: Add virtual user's initialization routines
  return lr.PASS;
}
  // ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int Actions()
{
try
{
lr.start_transaction("TestGetWithDrawOrderByCode");
System.Data.OracleClient.OracleConnection conn = new OracleConnection("User Id=test;Password=write;Data Source=escalade");
System.Data.OracleClient.OracleCommand comm = new OracleCommand();
comm.Connection = conn;
comm.CommandText = "BILL.GetWithDrawOrderByCode";
comm.CommandType = CommandType.StoredProcedure;
//輸入參數
System.Data.OracleClient.OracleParameter param1=comm.Parameters.Add("V_CODE",OracleType.VarChar,20);
param1.Direction = ParameterDirection.Input;
param1.Value ="TH15";
//輸出參數
System.Data.OracleClient.OracleParameter param2=comm.Parameters.Add("RETCURSOR",OracleType.Cursor);
param2.Direction = ParameterDirection.Output;
DataTable dt = new DataTable();
oracleDA = new System.Data.OracleClient.OracleDataAdapter();
oracleDA.SelectCommand = comm;
oracleDA.Fill(dt);
int iCount=Convert.ToInt32(dt.Rows.Count.ToString());
if(iCount>0)
lr.end_transaction("TestGetWithDrawOrderByCode",lr.PASS);
else
lr.end_transaction("TestGetWithDrawOrderByCode",lr.FAIL);
}
  catch(Exception ex)
{
string error = ex.Message;
}
  return lr.PASS;
}
  // ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int Terminate()
{
// TO DO: Add virtual user's termination routines
  return lr.PASS;
}
  }
}

  記得添加必要的引用,具體使用靈活掌握吧



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.