问:
在用MDB与SQL Server 2000链接时,有时需要刷新链接表,如何简洁方便地完成?
答:
通过以下代码可以达到目的:
Function relink() Dim db As Database Dim tbl As TableDef Dim a As String Dim b As String Dim d As String a = "sa"'数据库用户 b = "abc"'数据库口令 d = "abcde"'数据库名称 Set db = CurrentDb For Each tbl In db.TableDefs If tbl.Attributes = 536870912 Then tbl.Connect = "FILEDSN=d:demosteel.dsn;UID=" &a &"; PWD=" &b &";WSID=;DATABASE=" &d &";Network=DBMSSOCN" ' tbl.Attributes = dbAttachSavePWD tbl.RefreshLink End If Next End Function
问题解答如下:
1. DSN=gnts 中gnts是系统DSN的文件名。
2. UID是用户名,并且它的值由变量a的值决定。PWD是密码,并且它的值由变量b的值决定。
3. WSID 是指工作站的ID号 (Workstation ID)。变量d的值表示数据库的名称。 Network=DBMSSOCN 指TCP/IP所使用的网络库(Network Library)。