怎样在一个程序中连接两个数据库

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2017-06-13 17:06:09

  问:SOS 怎样在一个程序中连接两个数据库?数据库在两台机器中,一个是SQL6.5,一个是SQL7.0。

答:

你可以这么做
Transaction mytrans1,mytrans2
mytrans1=Create Transaction
mytrans2=Create Transaction
mytrans1.DBMS="驱动程序类型"
mytrans1.DBParm="这里填连接Sql6.5的字串"
mytrans2.DBMS="驱动程序类型"
mytrans1.DBParm="这里填连接Sql7.0的字串"
connect using mytrans1;
connect using mytrans2;
剩下的你知道该怎么做了?

eg:
Transaction mytrans1,mytrans2
mytrans1=Create Transaction
mytrans2=Create Transaction
mytrans1.DBMS = "ODBC"
mytrans1.AutoCommit = False
mytrans1.DBParm = "ConnectString='DSN=YourDsnforSql6.5DB'"
connect using mytrans1;
IF mytrans1.sqlcode = -1 THEN
Messagebox("",Yourmessage)
disconnect using mytrans1;
halt
end if

mytrans2.DBMS = "ODBC"
mytrans2.AutoCommit = False
mytrans2.DBParm = "ConnectString='DSN=YourDsnforSql7.0DB'"
connect using mytrans2;
IF mytrans2.sqlcode = -1 THEN
Messagebox("",Yourmessage)
disconnect using mytrans2;
halt
end if

//If t65 is a table in your sql6.5 Database,t70 is a table in your sql7.0 Database and
//dw_1 and dw_2 are DataWindow Control ,dwo_sql65 and dwo_sql70 are respectedly DataWindow Object
//for t65 and t70 then
dw_1.dataobject="dwo_sql65"
dw_1.settransobject(mytrans1)
dw_1.retrieve()//It is best to test error
dw_2.dataobject="dwo_sql70"
dw_2.settransobject(mytrans2)
dw_2.retrieve()//It's the same as above
//Then ,you can manipulate the data by dw_1 and dw_2
//Do you understand?


Tags:

作者:佚名
分享到: 微信 更多