加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

如何在 Access 2003 和 Access 2002 中搭建 DSN 的连接到 SQLServer 对链接

发布时间:2023-09-04 14:07:20 所属栏目:Asp教程 来源:
导读:方法 1: 使用 CreateTableDef 方法

CreateTableDef 方法可创建链接表。 若要使用此方法, 创建一个新模块, 然后以下 AttachDSNLessTable 函数添加到新模块。

复制代码 代码如下:

'//Name : At
方法 1: 使用 CreateTableDef 方法
 
CreateTableDef 方法可创建链接表。 若要使用此方法, 创建一个新模块, 然后以下 AttachDSNLessTable 函数添加到新模块。
 
复制代码 代码如下:
 
'//Name     :   AttachDSNLessTable
 
'//Purpose  :   Create a linked table to SQL Server without using a DSN
 
'//Parameters
 
'//     stLocalTableName: Name of the table that you are creating in the current database
 
'//     stRemoteTableName: Name of the table that you are linking to on the SQL Server database
 
'//     stServer: Name of the SQL Server that you are linking to
 
'//     stDatabase: Name of the SQL Server database that you are linking to
 
'//     stUsername: Name of the SQL Server user who can connect to SQL Server, leave blank to use a Trusted Connection
 
'//     stPassword: SQL Server user password
 
Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String)
 
    On Error GoTo AttachDSNLessTable_Err
 
    Dim td As TableDef
 
    Dim stConnect As String
 
    For Each td In CurrentDb.TableDefs
 
        If td.Name = stLocalTableName Then
 
            CurrentDb.TableDefs.Delete stLocalTableName
 
        End If
 
    Next
 
    If Len(stUsername) = 0 Then
 
        '//Use trusted authentication if stUsername is not supplied.
 
        stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
 
    Else
 
        '//WARNING: This will save the username and the password with the linked table information.
 

 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章