动态的连接到数据库的方法:
这里我们创建一个后缀为ini的文件system.ini,在system.ini文件中写入如下代码:
[dbms_profiles]
current=odbc
profiles=
[profile ]
dbms=
database=
userid=
databasepassword=
logpassword=
servername=
logid=
lock=
dbparm=connectstring='dsn=ora8;uid=;pwd=' //ora8指数据库服务器名
prompt=0
autocommit=0
这样在应用程序的open事件中写入下代码:
string ls_inifile
ls_inifile = "system.ini"
// profile system
sqlca.dbms =profilestring(ls_inifile,"database", "dbms", "")
sqlca.database =profilestring(ls_inifile,"database", "database", "")
sqlca.userid =profilestring(ls_inifile,"database", "userid", "")
sqlca.dbpass =profilestring(ls_inifile,"database", "dbpass", "")
sqlca.logid =profilestring(ls_inifile,"database", "logid", "")
sqlca.logpass =profilestring(ls_inifile,"database", "logpassword","")
sqlca.servername =profilestring(ls_inifile,"database", "servername" ,"")
sqlca.dbparm =profilestring(ls_inifile,"database", "dbparm", "")
connect using sqlca;
open(w_frame)
if sqlca.sqlcode<>0 then
messagebox("不能连接到数据库",sqlca.sqlerrtext)
return
end if
*****代码测试通过pb8.0