【发布时间】:2018-04-18 08:43:56
【问题描述】:
是否可以在包含failover partner 选项的 VBA Access 中使用 ADO 连接字符串?
我的连接代码如下所示:
Public Function OpenADOConnection() As Boolean
On Error GoTo err_trap
' Opens Global ADO Connection if it isnt already open.
' Returns TRUE if connected
Dim boolState As Boolean
If gcnn Is Nothing Then
Set gcnn = New ADODB.Connection ' if the global has not been instantiated or has been destroyed
End If
If gcnn.state = adStateOpen Then
boolState = True ' already open, nothing else to do
Else
gcnn.ConnectionString = "Data Source=SQL01;Failover Partner=SQL02;Initial Catalog=DBNAME;Integrated Security=True"
gcnn.Open
If gcnn.state = adStateOpen Then
boolState = True
Else
boolState = False ' cannot open connection so return false
End If
End If
OpenADOConnection = boolState ' return the connection state
exit_here:
Exit Function
err_trap:
OpenADOConnection = False
Call MsgBox("Unable to connect to the database. Please notify Database Administrator!" & vbCrLf & _
"(This error CANNOT be logged!", vbCritical, "ADO Connection Failed:", "", 0)
200 Resume exit_here
End Function
目前,它无法打开连接,所以我不确定我错过了什么,或者即使有可能实现这一点。
基本上我希望连接自动故障转移,而无需用户干预和知识。
【问题讨论】:
-
你能提供错误吗?
-
只说
Overflow没有什么帮助。 -
它是否仅适用于
Data Source=SQL02;- 未定义故障转移合作伙伴? -
是的,没有故障转移它工作正常
标签: ms-access vba connection-string