我在Excel VBA中创建了一个工具,该工具应该连接到Teradata并获取采购订单详细信息。它在我的笔记本电脑上正常工作,但当我与其他人共享该工具时,下面的连接字符串无法连接。在他们的笔记本电脑上进行故障排除时,我看到用户可以使用SQL助手连接到Teradata。但Excel VBA字符串根本不连接。
在函数运行下面,CN.state总是返回' 0'
Function Connect(Server As String, Database As String) As Boolean
Set CN = New ADODB.Connection
On Error Resume Next
Dim UserId As String
Dim Password As String
Call CenterLoginWindow
'Input UserID and Password here
UserId = Login.Username
Password = Login.Password
With CN
' Create connecting string
.ConnectionString = "Data Source=" & Server & ";" & _
"Database=" & Database & ";" & _
"Persist Security Info=True;Session Mode=ANSI;" & _
"Uid=" & UserId & ";" & _
"Pwd=" & Password & ""
.CommandTimeout = 0
' Open connection
.Open
End With
' Check connection state
If CN.State = 0 Then
Connect = False
Else
Connect = True
End If
End Function
答案 0 :(得分:0)
我有一些问题要问你: 1.某些其他域中的用户是否需要使用不同的连接字符串? 2.他们尝试连接时会出现什么错误?我在上面的代码中没有看到任何错误处理。 3.我发现你指定的超时时间非常短。你试过加长吗?