RDO之Informix与VB的连结

  • 发布于:2024-02-20
  • 129 人围观

透过OpenLink Generic 32 Bit Driver与Informix 7.2 连结 ,当然,如果是SQL SERVER

的连结也是大同小异啦。

至于连结完之后如何操作DataBase内的资料,请查RDO 的建立记录集(一)

无DSN的建立连结,好处是不用每一台电脑去控制台ODBC32中设定一个Data Source,

而且也不用在Hosts中设定Server所在电脑的IP Address。方式

Private cn As rdoConnectionPrivate en As rdoEnvironmentDim connstr As StringSet en = rdoEnvironments(0)connstr = "UID=cww;PWD=cww1111;Database=cwwpf@eis;" _+ "Driver={OpenLink Generic 32 Bit Driver};" _+ "Host=192.168.0.61;" _+ "ServerType=Informix 7.2;"Set cn = en.OpenConnection("", rdDriverNoPrompt, _ False, connstr)‘会等OpenConnection执行 成功/失败 后才会往下做下去

而建立有DSN的建立连结方式(有一Data Source Name 叫OPNK)

Dim connstr As StringSet en = rdoEnvironments(0)connstr = "UID=cww;PWD=cww1111;"Set cn = en.OpenConnection("OPNK", rdDriverNoPrompt, _ False, connstr)‘会等OpenConnection执行 成功/失败 后才会往下做下去如果想在在执行OpenConnection 方法后立即交出控制权,那必需用以下的方式:1.OpenConnection时要有rdAsyncEnable才行(即非同步开启)2.cn要以WithEvents来宣告(如果想使用Connect事件来Check是否有成功)Private WithEvents cnAs rdoConnectionPrivate en As rdoEnvironment‘不管Connect成功与否,都会引发Connect的事件Private Sub cn_Connect(ByVal ErrorOccurred As Boolean)Dim i As LongDim er As rdoErrorIf ErrorOccurred Then ‘连结失败 Debug.Print Err.Description, Error For Each er In rdoErrorsDebug.Print er.Description, er.Number Next erElse‘连结成功For i = 0 To cn.rdoTables.Count1 Debug.Print cn.rdoTables(i).NameNextEnd IfEnd SubPrivate Sub Form_Load()Dim connstr As StringSet en = rdoEnvironments(0)connstr = "UID=cww;PWD=cww1111;"Set cn = en.OpenConnection("OPNK", rdDriverNoPrompt, _ False, connstr, rdAsyncEnable)‘Do While cn.StillConnecting ‘如果不使用Connect事件,那要用以下方式‘ DoEvents‘LoopEnd Sub

当然了,我们也可以使用rdoConnection的EstablishConnection的方法来做,而使用EstablishConnection时,却是内定的会产生Connect事件(只要rdoConnection物件以WithEvents宣告)例如:Set en = rdoEnvironments(0)Set cn = New rdoConnectioncn.CursorDriver = rdUseODBCconnstr = "DSN=SQLSRV;UID=cww;PWD=cww1111;"cn.Connect = connstrcn.EstablishConnection rdDriverNoPrompt, False

万企互联
标签: