• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Connect other back up databased if DB pri fail

marreco

Member
Hi.
How connect other database, case database1 fail?
I have 2 database (backup DB), case my first DB fail i need connect DB2.

Code:
Sub ConnectBDServer2CaseBDServer1Fail()

Dim connection As ADODB.connection
Dim recordSet As ADODB.recordSet
Dim stringSQL As String

Const sADO As String = "Provider=SQLOLEDB;Server=SERVER1;" & _
"DBServer1=MyDBServer1;" & "User Id=UserOne;Password=MyPassword;"
'Case databse1 out(fail connection), i need connect with databse2 (backup database)
   
End Sub

Thank you!!
 
Like this?
Code:
Sub ConnectBDServer2CaseBDServer1Fail()

Dim connection As ADODB.connection
Dim recordSet As ADODB.recordSet
Dim stringSQL As String

On Error GoTo ConnDB2
Const sADO As String = "Provider=SQLOLEDB;Server=SERVER1;" & _
"DBServer1=MyDBServer1;" & "User Id=UserOne;Password=MyPassword;"
'Case databse1 out(fail connection), i need connect with databse2 (backup database)
ConnDB2:
'my connection backup here?

End Sub
 
Yes, but make sure to check for "Err.Number" after "ConnDB2:" and only run code when it's not "0".
 
Back
Top