Can I have a second TRY inside the first TRY/CATCH in ASP.NET ???

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




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


.



Relevant Pages

  • Re: Newbie with Database Connection Problem
    ... Verify the connection string, the values of the paramaters etc ... > Dim Con As New OleDb.OleDbConnection ... > Private Sub Login_Load(ByVal sender As System.Object, ... > ' Close database connection ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: ADO connections question
    ... Function CreateADOObjects(ConnectionString as string) ... you'll see this error if the connection has not been ... I have a specific login form that calls the dbLogin function as shown ... Dim strCriteria As String ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Updating Access data using SQL / refresh time question
    ... As a test today, for one poarticular recordset, I changed from DAO to ADO to ... > I forgot to mention that the expense of repeated connection open and close ... > dim oconn as new adodb.connection ... > 'Now load the listview by looping through each RS row ...
    (microsoft.public.vb.database)
  • Re: Updating Access data using SQL / refresh time question
    ... > I forgot to mention that the expense of repeated connection open and close ... > dim oconn as new adodb.connection ... > 'Now load the listview by looping through each RS row ... > ' Set the recordset object each time we load the listview ...
    (microsoft.public.vb.database)
  • Re: Updating Access data using SQL / refresh time question
    ... > I forgot to mention that the expense of repeated connection open and close ... > dim oconn as new adodb.connection ... > 'Now load the listview by looping through each RS row ... > ' Set the recordset object each time we load the listview ...
    (microsoft.public.vb.database)