【问题标题】:MS Access ADO connection string with Failover Partner option带有故障转移伙伴选项的 MS Access ADO 连接字符串
【发布时间】: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


【解决方案1】:

我没有看到Provider 在您的连接字符串中的任何位置定义。这是一个普遍的问题。

我从未在 ADO 中使用过故障转移选项,但我很确定旧的 OLE DB 提供程序 (SQLOLEDB) 不支持它们。相反,您应该使用全新的Microsoft OLE DB Driver for SQL Server (msoledbsql)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 2015-10-28
    • 2010-10-09
    • 2011-11-08
    • 1970-01-01
    • 2012-03-24
    • 2011-10-15
    相关资源
    最近更新 更多