Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 尝试使用attachdsnlestable函数时出错_Sql_Sql Server 2008_Ms Access_Vba - Fatal编程技术网

Sql 尝试使用attachdsnlestable函数时出错

Sql 尝试使用attachdsnlestable函数时出错,sql,sql-server-2008,ms-access,vba,Sql,Sql Server 2008,Ms Access,Vba,我正在尝试使用无dsn连接连接到SQL Server 2008。我正在尝试使用AttachDSNLessTable例程,但未能使其正常工作。我明白了 运行时错误“2425”输入的表达式具有microsoft Access找不到的函数名 我有一个名为AutoExec的宏,它运行代码attachdsnlestable 我在AutoExec宏中写道: AttachDSNLessTable ("Land", "dbo.Land", "ABZAL", "Pdata", "sa", "294285") A

我正在尝试使用无dsn连接连接到SQL Server 2008。我正在尝试使用AttachDSNLessTable例程,但未能使其正常工作。我明白了

运行时错误“2425”输入的表达式具有microsoft Access找不到的函数名

我有一个名为AutoExec的宏,它运行代码attachdsnlestable

我在AutoExec宏中写道:

AttachDSNLessTable ("Land", "dbo.Land", "ABZAL", "Pdata", "sa", "294285")
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
附件SNLESSTABLE\u错误:

AttachDSNLessTable = False
MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description
端函数

下面是我使用方法1的源代码的链接

请帮帮我