一是:通过odbc,在database-odbc-utilities-双击odbcadministrator,添加数据源,
上图:
添加新的数据源
上图:为数据源选择驱动程序
上图:这里data
source
name栏中输入数据库名,tns
servicename栏输入(选择)服务器名:。然后完成,单击ok
上图:在新建proflie与数据库相连
添上profile
name,还有data
source
,userid
,password,这样就加上了数据库,在connect就可以用了
可以的,PB中同时连接多个数据库,如连接SQLServer2000和Oracle8 ,代码如下:string ls_startupfile
ls_startupfile='hisini.ini'
sqlca.DBMS = ProfileString(ls_startupfile, "database", "dbms", "")
sqlca.database = ProfileString(ls_startupfile, "database", "database", "")
sqlca.userid = ProfileString(ls_startupfile, "database", "userid", "")
sqlca.dbpass = ProfileString(ls_startupfile, "database", "dbpass", "")
sqlca.logid = ProfileString(ls_startupfile, "database", "logid", "")
sqlca.logpass = ProfileString(ls_startupfile, "database", "LogPassWord", "")
sqlca.servername = ProfileString(ls_startupfile, "database", "servername", "")
sqlca.dbparm = ProfileString(ls_startupfile, "database", "dbparm", "")
remote_trans= CREATE transaction
remote_trans.DBMS = ProfileString(ls_startupfile, "Database_remote", "dbms", "")
remote_trans.database = ProfileString(ls_startupfile, "Database_remote", "database", "")
remote_trans.userid = ProfileString(ls_startupfile, "database_remote", "userid", "")
remote_trans.dbpass = ProfileString(ls_startupfile, "database_remote", "dbpass", "")
remote_trans.logid = ProfileString(ls_startupfile, "database_remote", "logid", "")
remote_trans.logpass = ProfileString(ls_startupfile, "database_remote", "LogPassWord", "")
remote_trans.servername = ProfileString(ls_startupfile, "database_remote", "servername", "")
remote_trans.dbparm = ProfileString(ls_startupfile, "database_remote", "dbparm", "")
//附hisini.ini
[Database]
DBMS=MSS Microsoft SQL Server 6.x
Database=his
UserId=
DatabasePassword=
ServerName=.
LogId=sa
Lock=
Prompt=0
computer='11'
ocx= 0
use0='之住院管理'
cfprint='1'
[Database_remote]
DBMS = "O84 Oracle8/8i(8.x.4+)"
ServerName = "oracle8"
LogId = "dba"
Database=zx
UserId=
DatabasePassword=
Lock=
Prompt=0
computer='11'
ocx= 0
cfprint='1'
给你copy一段吧:PB连接多个数据库
2007-11-29 13:54:23| 分类: PB | 标签: |字号大中小 订阅
声明多个Transaction变量
Transaction SQLCA, SQLCB
SQLCA = Create
Transaction
SQLCB = Create
Transaction
然后做相应配置
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm =
"ConnectString='DSN=********UID=***PWD=*******"
SQLCB.DBMS = "ODBC"
SQLCB.AutoCommit = False
SQLCB.DBParm = "ConnectString='DSN=*******UID=******PWD=*******'"
使用的时候直接用Connect Using SQLCA就可以连接上SQLCA所对应的数据库,使用Connect Using
SQLCB则可以连接上SQLCB所对应的数据库,可以在程序中保持同时和多个数据库的连接,而不需要在连接使用完后DISCONNECT,因为频繁的使用CONNECT与DISCONNECT可能会导致很多意想不到的问题发生。
要注意的是:当我们在程序中使用SELECT等SQL语句时,PB默认的是使用SQLCA进行数据库连接,所以当使用SELECT等SQL语句的时候,必须在末尾加上USING
******
比如:
Select Name
Into: Ls_Name
From
Students
Where Number = :Ls_Number
Using NewTransaction
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)