B
bienwell
Hi all,
I'd like to use TRY, CATCH to open my database connection. I have 2 servers
that have the same table name "myTable". If the first connection to Server1
is failed, then the program will try to connect to Server2. Can I have the
secong Try inside the first Catch for this purpose ?. Please take a look on
my code and fix it if possible. Actually with this code, the database
connection with Server2 is opened after the first connection to Server1 is
failed.
Thanks in advance .
Dim myStr As String ="Select * from myTable"
Dim myConnection as ODBCConnection
Dim myCommand as ODBCCommand
Dim myRec as ODBCDataReader
Dim strConn as string =
"server=Server1;uid=UserID1;pwd=Password1;DSN=Server1"
Dim strConn as string =
"server=Server2;uid=UserID2;pwd=Password2;DSN=Server2"
Try
myConnection = New ODBCConnection(strConn)
myConnection.Open()
myCommand = New OdbcCommand(myStr, myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close
Dim myDataSet as DataSet=GetDataSource()
myDataList.DataSource = myDataSet
myDataList.DataBind()
Catch Exc1 As Exception
Try
myConnection = New ODBCConnection(strConn2)
myConnection.Open()
myCommand = New OdbcCommand(myStr, myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close
Dim myDataSet as DataSet=GetDataSource()
myDataList.DataSource = myDataSet
myDataList.DataBind()
Catch Exc2 As Exception
response.write("<BR>Database connection is failed ..")
End Try
End Try
I'd like to use TRY, CATCH to open my database connection. I have 2 servers
that have the same table name "myTable". If the first connection to Server1
is failed, then the program will try to connect to Server2. Can I have the
secong Try inside the first Catch for this purpose ?. Please take a look on
my code and fix it if possible. Actually with this code, the database
connection with Server2 is opened after the first connection to Server1 is
failed.
Thanks in advance .
Dim myStr As String ="Select * from myTable"
Dim myConnection as ODBCConnection
Dim myCommand as ODBCCommand
Dim myRec as ODBCDataReader
Dim strConn as string =
"server=Server1;uid=UserID1;pwd=Password1;DSN=Server1"
Dim strConn as string =
"server=Server2;uid=UserID2;pwd=Password2;DSN=Server2"
Try
myConnection = New ODBCConnection(strConn)
myConnection.Open()
myCommand = New OdbcCommand(myStr, myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close
Dim myDataSet as DataSet=GetDataSource()
myDataList.DataSource = myDataSet
myDataList.DataBind()
Catch Exc1 As Exception
Try
myConnection = New ODBCConnection(strConn2)
myConnection.Open()
myCommand = New OdbcCommand(myStr, myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close
Dim myDataSet as DataSet=GetDataSource()
myDataList.DataSource = myDataSet
myDataList.DataBind()
Catch Exc2 As Exception
response.write("<BR>Database connection is failed ..")
End Try
End Try