分类:
2009-10-11 11:17:37
来源:cww 透过OpenLink Generic 32 Bit Driver与Informix 7.2 连结 ,当然,如果是SQL SERVER 的连结也是大同小异啦。 至于连结完之后如何操作DataBase内的资料,请查RDO 的建立记录集(一) 无DSN的建立连结,好处是不用每一台电脑去控制台ODBC32中设定一个Data Source, 而且也不用在Hosts中设定Server所在电脑的IP Address。方式如下:
Private cn As rdoConnection Private en As rdoEnvironment Dim connstr As String Set 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执行 成功/失败 后才会往下做下去 |
Dim connstr As String Set 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 cn As rdoConnection Private en As rdoEnvironment '不管Connect成功与否,都会引发Connect的事件 Private Sub cn_Connect(ByVal ErrorOccurred As Boolean) Dim i As Long Dim er As rdoError If ErrorOccurred Then '连结失败 Debug.Print Err.Description, Error For Each er In rdoErrors Debug.Print er.Description, er.Number Next er Else '连结成功 For i = 0 To cn.rdoTables.Count - 1 Debug.Print cn.rdoTables(i).Name Next End If End Sub Private Sub Form_Load() Dim connstr As String Set en = rdoEnvironments(0) connstr = "UID=cww;PWD=cww1111;" Set cn = en.OpenConnection("OPNK", rdDriverNoPrompt, _ False, connstr, rdAsyncEnable) 'Do While cn.StillConnecting '如果不使用Connect事件,那要用以下方式 ' DoEvents 'Loop End Sub |
当然了,我们也可以使用 rdoConnection的EstablishConnection的方法来做,而使用EstablishConnection 时,却是内定的会产生Connect事件(只要rdoConnection物件以WithEvents宣告) 例如: Set en = rdoEnvironments(0) Set cn = New rdoConnection cn.CursorDriver = rdUseODBC connstr = "DSN=SQLSRV;UID=cww;PWD=cww1111;" cn.Connect = connstr cn.EstablishConnection rdDriverNoPrompt, False