PowerBuilder直接导出数据库连接文件INI的方法


直接导出数据库连接文件的方法:

1)在PB中连接到目的数据库,然后点击右键,选择“Export Profile(s)”,在弹出的“Export Profile(s)”窗口中已经默认选中了当前连接的数据库,直接点击“OK”

2)在弹出的“Select Profile File”窗口中选择ini文件的路径,一般就是程序的目录下,填写ini文件的名字,譬如dblink,就会生成一个dblink.ini的文件

3)打开dblink.ini文件,内容如下
[DBMS_PROFILES]
Profiles=mzsf
[Profile mzsf]
DBMS=O90 Oracle9i (9.0.1)
Database=
UserId=
DatabasePassword=
LogId=mzsf
LogPassword=test
ServerName=testserver
DBParm=PBCatalogOwner='test'
Lock=
Prompt=FALSE
AutoCommit=FALSE

可按具体情况进行修改,譬如删除
[DBMS_PROFILES]
Profiles=mzsf
[Profile mzsf]

然后再添加上[Database],完整内容如下
[Database]
DBMS=O90 Oracle9i (9.0.1)
Database=
UserId=
DatabasePassword=
LogId=mzsf
LogPassword=test
ServerName=testserver
DBParm=PBCatalogOwner='test'
Lock=
Prompt=FALSE
AutoCommit=FALSE

3、写入读取ini文件的语句,使用默认的SQLCA。

可以在需要的地方写上如下内容(譬如在Application的open事件中)
string str_file
//获取数据库配置文件,目录相对当前应用程序根目录
str_file = "dbtest.ini"
// 判断指定的INI文件是否存在
if not FileExists (str_file) then
   messagebox("提示!","ini文件不存在!",exclamation!,ok!,2)
 return
end if

SQLCA.DBMS       = ProfileString(str_file,"database","DBMS"," ")
SQLCA.Database   = ProfileString(str_file,"database","DataBase"," ")
SQLCA.LogID      = ProfileString(str_file,"database","LogID"," ")
SQLCA.LogPass    = ProfileString(str_file,"database","LogPassword"," ")
SQLCA.ServerName = ProfileString(str_file,"database","ServerName"," ")
SQLCA.UserID     = ProfileString(str_file,"database","UserID"," ")
SQLCA.DBPass     = ProfileString(str_file,"database","DatabasePassword", " ")
SQLCA.Lock       = ProfileString(str_file,"database","Lock"," ")
SQLCA.DbParm     = ProfileString(str_file,"database","dbparm"," ")
SQLCA.autocommit = false
//默认使用SQLCA,否则应该
//connect using ...
connect;
open(w_login)

在必要的地方关闭连接,譬如Application的close事件

//默认使用SQLCA,否则应该
//disconnect using ...
disconnect;

4、添加窗口、控件,使用SQL语句读取数据。
       为了在下面一步中点击exe文件也能连接到数据库,在放置数据窗口对象的窗口中选中数据窗口控件,在open事件中添加如下代码


dw_1.settrans(sqlca)
dw_1.retrieve( )

5、生成exe和dll文件。
       选择“File - New”,在“New”窗口中选择“Project”标签页,选择“Application Wizard”,其余步骤按提示完成即可,最后关闭所有的窗口,在当前项目工作区上点击右键,选择“Deploy”,就能生成exe和dll文件了(在“Application Wizard”中设置了生成exe和dll)。

6、基本就完成一个简单的连接数据库的系统。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值