Wenn Sie zwischen SQL Server nicht festgelegt haben, Spiegelung, können Sie dies erreichen, indem .NET. einfach in einer Fangaussage.
-Code unten ..
enter code here
Imports System.Data.SqlClient
Imports System.Data
Public Class dbConn
Private primaryServerLocation As String = "SERVER=primaryAddress;DATABASE=yourDB;User id=youruserID;Password=yourPassword;"
Private secondaryServerLocation As String = "SERVER=secondaryAddress;DATABASE=yourDB;User id=youruserID;Password=yourPassword;"
Public sqlConnection As SqlConnection
Public cmd As SqlCommand
Public Sub primaryConnection()
Try
sqlConnection = New System.Data.SqlClient.SqlConnection(primaryServerLocation)
cmd = New System.Data.SqlClient.SqlCommand()
'test connection
sqlConnection.Open()
sqlConnection.Close()
Catch ex As Exception
secondaryConnection()
End Try
End Sub
Public Sub secondaryConnection()
'Used as the failover secondary server if primary is down.
Try
sqlConnection = New System.Data.SqlClient.SqlConnection(secondaryServerLocation)
cmd = New System.Data.SqlClient.SqlCommand()
'test connection
sqlConnection.Open()
sqlConnection.Close()
Catch ex As Exception
End Try
End Sub
End Class
Hallo Joel, Vielen Dank für Ihre resposne, wird diese Arbeit, auch wenn ich nicht habe Spiegelung Setup? – Vineet
Kann ich dieselben für AD Connection-Zeichenfolgen verwenden, um eine Failover-LDAP-Verbindung anzugeben? –