LoadRunner利用ODBC连接Oracle

LoadRunner中,编辑脚本的时候,经常要创建 参数,从而更真实的模拟用户操作。下面介绍tabel类型的参数,这种参数 的数据源直接来自数据库。下面以ORACLE 数据库为例。

可能首先要安装ORACLE的客户端,这样才能连接ORACLE数据库服务器,如果是SQL Server的话,就不用这么麻烦了。

1. ODBC连接数据库

首先要用ODBC连接数据库,创建文件DSN。打开ODBC

<!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter" /> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0" /> <v:f eqn="sum @0 1 0" /> <v:f eqn="sum 0 0 @1" /> <v:f eqn="prod @2 1 2" /> <v:f eqn="prod @3 21600 pixelWidth" /> <v:f eqn="prod @3 21600 pixelHeight" /> <v:f eqn="sum @0 0 1" /> <v:f eqn="prod @6 1 2" /> <v:f eqn="prod @7 21600 pixelWidth" /> <v:f eqn="sum @8 21600 0" /> <v:f eqn="prod @7 21600 pixelHeight" /> <v:f eqn="sum @10 21600 0" /> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" /> <o:lock v:ext="edit" aspectratio="t" /> </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:330pt; height:268.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.png" o:title="" /> </v:shape><![endif]-->

<!--[if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75" style='width:345.75pt;height:285pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image003.png" o:title="" /> </v:shape><![endif]-->

如上图,点“添加”,选择驱动,对于Oracle数据库,有2种驱动程序:“Microsoft ODBC for Oracle”和“Oracle in OraHome92(这个驱动,在安装ORACLE的客户端的时候,会安装的。)。

1.1. 利用Microsoft ODBC for Oracle驱动连接

这里先选择“Microsoft ODBC for Oracle”,

<!--[if gte vml 1]><v:shape id="_x0000_i1027" type="#_x0000_t75" style='width:350.25pt;height:260.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image005.png" o:title="" /> </v:shape><![endif]-->

点下一步,

<!--[if gte vml 1]><v:shape id="_x0000_i1028" type="#_x0000_t75" style='width:365.25pt;height:307.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image007.png" o:title="" /> </v:shape><![endif]-->

默认的保存路径是:C:\Program Files\Common Files\ODBC\Data Sources,输入名字,点保存,点“下一步”,点“完成”,

<!--[if gte vml 1]><v:shape id="_x0000_i1029" type="#_x0000_t75" style='width:242.25pt;height:96pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image009.png" o:title="" /> </v:shape><![endif]-->

输入:用户名,密码,服务器(本地ORACLE客户端上配置的SID),然后就做好文件DSN了。

<!--[if gte vml 1]><v:shape id="_x0000_i1030" type="#_x0000_t75" style='width:415.5pt;height:267pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image011.png" o:title="" /> </v:shape><![endif]-->

1.2. 利用Oracle in OraHome92驱动连接

用这种驱动,就最后一步不同,如下图,Service Name填入(本地ORACLE客户端上配置的SID)。

<!--[if gte vml 1]><v:shape id="_x0000_i1031" type="#_x0000_t75" style='width:201.75pt;height:160.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image013.png" o:title="" /> </v:shape><![endif]-->

2. LR中的“Table”类型参数设置

Virtual User Generator 中,打开一个脚本的 “参数列表” 窗口,如下图:

<!--[if gte vml 1]><v:shape id="_x0000_i1032" type="#_x0000_t75" style='width:414.75pt;height:373.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image015.png" o:title="" /> </v:shape><![endif]-->

点“new”新建一个参数,选择类型为table,然后点“data Wiszard…”(向导),

<!--[if gte vml 1]><v:shape id="_x0000_i1033" type="#_x0000_t75" style='width:335.25pt;height:255.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image017.png" o:title="" /> </v:shape><![endif]-->

如上图,选择Specify SQL statement manually,下一步,点“Create…

<!--[if gte vml 1]><v:shape id="_x0000_i1034" type="#_x0000_t75" style='width:335.25pt;height:255.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image019.png" o:title="" /> </v:shape><![endif]-->

<!--[if gte vml 1]><v:shape id="_x0000_i1035" type="#_x0000_t75" style='width:335.25pt;height:291.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image021.png" o:title="" /> </v:shape><![endif]-->

选择刚才创建的连接ORACLE的 文件DSN

<!--[if gte vml 1]><v:shape id="_x0000_i1036" type="#_x0000_t75" style='width:198.75pt;height:159.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image023.png" o:title="" /> </v:shape><![endif]-->

输入密码,

创建SQL 语句,如果是SQL Server的话,SQL语句有点不一样,

/************************/

Use (数据库名)

SELECT loginID,sex

FROM users

/************************/

<!--[if gte vml 1]><v:shape id="_x0000_i1037" type="#_x0000_t75" style='width:336.75pt;height:256.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image025.png" o:title="" /> </v:shape><![endif]-->

finish,然后就可以看到结果:

<!--[if gte vml 1]><v:shape id="_x0000_i1038" type="#_x0000_t75" style='width:415.5pt;height:231pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image027.png" o:title="" /> </v:shape><![endif]-->

Edit with Notepad,在记事本中,可以看到全部的数据。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值