国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

如何在 Access 2003 和 Access 2002 中創建 DSN 的連接到 SQLServer 對鏈接

2024-05-04 10:59:00
字體:
來源:轉載
供稿:網友
方法 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.
        stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
    End If
    Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
    CurrentDb.TableDefs.Append td
    AttachDSNLessTable = True
    Exit Function
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巴彦县| 汪清县| 毕节市| 新宾| 团风县| 江孜县| 雅江县| 韶关市| 永善县| 隆子县| 安乡县| 南投市| 疏勒县| 平谷区| 额尔古纳市| 宜黄县| 厦门市| 伊宁市| 孟村| 扶风县| 甘南县| 杭州市| 石屏县| 兴宁市| 濮阳市| 聂荣县| 株洲市| 莱州市| 姜堰市| 石台县| 孟村| 上蔡县| 宽城| 双江| 萍乡市| 澳门| 中阳县| 宁明县| 临洮县| 孟州市| 庆元县|