Office中国论坛/Access中国论坛

标题: 怎么样自动链接ODBC [打印本页]

作者: jhzlzc29    时间: 2003-4-17 01:43
标题: 怎么样自动链接ODBC
请问怎么自动链接ODBC?
作者: sunredday    时间: 2003-4-17 05:13
关注
谁能给举一个例子
作者: 竹笛    时间: 2003-4-17 05:36
请用搜索功能,我以前好象看到有网友发过类似的帖子,好象是zhuyiwen回答的。

作者: jhzlzc29    时间: 2003-4-17 06:24
zhuyiwen版主是回答了,可是我看不懂是什么意思,本人英文实在是不行,可否翻一下
http://www.mvps.org/access/tables/tbl0010.htm
作者: 竹笛    时间: 2003-4-17 07:07
生平我最恨洋文,以下是我乱译一气,请英语好的网友帮忙完善一下:

Personally, I find the manual steps required to link to an ODBC table rather annoying.  If you feel the same way, here's how to automate the whole process.

    I'd suggest creating a table with three fields,
手动链接ODBC烦死了,如果你有同感,这里将告诉您如何自动连接ODBC。建议创建一个表,表中有三个字段。

LocalTableName -- The name of the ODBC table as it appears in the Database window.
客户端表
ConnectString -- The complete connect string to the ODBC Table. (Can be viewed by
连接表
?CurrentDB.TableDefs("SomeODBCTable").Connect

SourceTable -- The actual name of the ODBC table in the Data source. May be the same as Local Table Name.
服务器表--要求服务器中的表与客户端数据库中的表名一致
Store this information for all ODBC tables in this table (referred to as tblReconnectODBC in code).  The benefit is that when this code is run in a new mdb, it re-creates a tabledef for each entry in this table if no ODBC Links are found in the database.

    If you want, you can also add RegisterDatabase method to this code when the DSNs are not found in registry. I, unfortunately, haven't had any luck with it since I'm dealing with Oracle.


'****************** Code Start *********************>
' This code was originally written by Dev Ashish.
'本代码的原作者为dew ashish
' It is not to be altered or distributed,

' except as part of an application.
'未经允许不得更改或分发
' You are free to use it in any application,
' provided the copyright notice is left unchanged.

' Code Courtesy of
' Dev Ashish
''您可无偿使用但请在代码中注明原作者:Dev Ashish
Option Compare Database
Option Explicit

Private Type tODBCInfo
    strTableName As String
    strNewName As String
    strConnectString As String
    strSourceTable As String
End Type

'Contains all info for tables
Private mastODBCInfo() As tODBCInfo

'*** Registry stuff
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_DYN_DATA = &H80000006
Private Const STANDARD_RIGHTS_READ = &H20000
Private Const KEY_QUERY_VALUE = &H1&
Private Const KEY_ENUMERATE_SUB_KEYS = &H8&
Private Const KEY_NOTIFY = &H10&
Private Const Synchronize = &H100000
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or _
                        KEY_QUERY_VALUE Or _
                        KEY_ENUMERATE_SUB_KEYS Or _
                        KEY_NOTIFY) And _
                        (Not Synchronize))
Private Const MAXLEN = 256
Private Const ERROR_SUCCESS = &H0&
Const REG_NONE = 0
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_DWORD_LITTLE_ENDIAN = 4
Const REG_DWORD_BIG_ENDIAN = 5
Const REG_LINK = 6
Const REG_MULTI_SZ = 7
Const REG_RESOURCE_LIST = 8

Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Private Declare Function apiRegOpenKeyEx Lib "advapi32.dll" _
        Alias "RegOpenKeyExA" _
        (ByVal hKey As Long, _
        ByVal lpSubKey As String, _
        ByVal ulOptions As Long, _
        ByVal samDesired As Long, _
        ByRef phkResult As Long) _
        As Long

Private Declare Function apiRegCloseKey Lib "advapi32.dll" _
        Alias "RegCloseKey" _
        (ByVal hKey As Long) _
        As Long

Private Declare Function apiRegQueryValueEx Lib "advapi32.dll" _
        Alias "RegQueryValueExA" _
        (ByVal hKey As Long, _
        ByVal lpValueName As String, _
        ByVal lpReserved As Long, _
        ByRef lpType As Long, _
        lpData As Any, _
        ByRef lpcbData As Long) _
        As Long

Private Declare Function apiRegQueryInfoKey Lib "advapi32.dll" _
        Alias "RegQueryInfoKeyA" _
        (ByVal hKey As Long, _
        ByVal lpClass As String, _
        ByRef lpcbClass As Long, _
        ByVal lpReserved As Long, _

作者: cg1    时间: 2003-4-17 07:22
别告诉我他注册odbc用写注册表的方法阿!????
我会疯掉的,呵呵
作者: jhzlzc29    时间: 2003-4-17 16:58
以下是引用cg1在2003-4-16 23:21:35的发言:
别告诉我他注册odbc用写注册表的方法阿!????
我会疯掉的,呵呵

不会吧,真的吗?
作者: jhzlzc29    时间: 2003-4-17 17:08
能否做个具体引用的例子
作者: jhzlzc29    时间: 2003-4-17 17:10
对了还有一个问题,怎么使SQL远程应用链接怎么实现功能呢?




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3