在创建数据库连接时,怎样从文件中读取连接数据库的用户名和密码?

xiaoqiangteng 2004-08-11 11:00:05
pb在与数据库连接的时候,数据库的用户名和密码一般是在应用程序对象的open事件中写死的,这样万一数据库的用户名或是密码一改动,pb应用程序也得改动(还得重新编译),这样显得很是麻烦,请问哪位大侠有办法可以在pb与数据库创建连接的时候,从其他文件(如*.TXT文件什么的)中把用户名和密码读取出来,再创建连接?
...全文
156 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yzh963 2004-08-11
没有加密服务器,上面方法可行,就是不安全,最好加入简单的算法,不让人一眼就看到user 和password
回复
sywen 2004-08-11
up
回复
qiqiu999 2004-08-11
startupfile=wrkpath+"\**.ini"
sqlca.DBMS = profileString (startupfile, "database", "dbms", "")
sqlca.database = ProfileString (startupfile, "database", "database", "")
sqlca.userid = ProfileString (startupfile, "database", "userid", "")
sqlca.dbpass = ProfileString (startupfile, "database", "dbpass", "")
sqlca.logid = ProfileString (startupfile, "database", "logid", "")
sqlca.logpass = ProfileString (startupfile, "database", "LogPassWord", "")
sqlca.servername = ProfileString (startupfile, "database", "servername", "")
sqlca.dbparm = ProfileString (startupfile, "database", "dbparm", "")
connect;
回复
liubocy 2004-08-11
程序根目录下config.txt内容:
[Database]
DBMS=SYC Sybase System 10/11
Database=taxpayerdeclare_sc
UserId=
dbpass=
LogPassword=aaaaaa
ServerName=develop01
LogId=controller
Lock=
DbParm=CharSet='cp850'

连接代码:

String ls_config = 'config.txt'

sqlca.DBMS = ProfileString (ls_config, "database", "dbms", " ")
sqlca.database = ProfileString (ls_config, "database", "database", " ")
sqlca.userid = ProfileString (ls_config, "database", "userid", " ")
sqlca.dbpass = ProfileString (ls_config, "database", "dbpass", " ")
sqlca.logid = ProfileString (ls_config, "database", "logid", " ")
sqlca.logpass = ProfileString (ls_config, "database", "LogPassWord"," ")
sqlca.servername = ProfileString (ls_config, "database", "servername", " ")
sqlca.dbparm = ProfileString (ls_config, "database", "dbparm", " ")
sqlca.Lock = ProfileString (ls_config, "database", "Lock", " ")

connect;

if sqlca.sqlcode <> 0 then
MessageBox ("Cannot Connect to Database", sqlca.sqlerrtext)
return
end if
回复
rock_csdn 2004-08-11
密码在检测到是明文配置后,读取后立即改写成密文。
回复
xiaoqiangteng 2004-08-11
我这儿用的是db2数据库,连接用的是odbc数据源,请问上面的设置需要怎么改?
回复
相关推荐
发帖
数据库相关
创建于2007-09-28

738

社区成员

PowerBuilder 数据库相关
申请成为版主
帖子事件
创建了帖子
2004-08-11 11:00
社区公告
暂无公告