国产探花免费观看_亚洲丰满少妇自慰呻吟_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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 仪陇县| 东莞市| 盐池县| 东乌| 买车| 易门县| 揭东县| 双柏县| 赣榆县| 同江市| 涡阳县| 大丰市| 吉安市| 旬阳县| 榆林市| 湖南省| 盱眙县| 陕西省| 鹤壁市| 阜阳市| 靖州| 万宁市| 曲麻莱县| 宁乡县| 定安县| 临沧市| 巴林左旗| 宜宾县| 峨眉山市| 玛曲县| 沙湾县| 宜川县| 修武县| 巍山| 莎车县| 中山市| 潼关县| 彭阳县| 汽车| 大洼县| 礼泉县|