Server down redirect

Posted on 2009-02-10
Last Modified: 2012-05-06
Hey folks,
  I'm using SQL Database as my datasource.  What is the best method to look at a different server if server one is down.

I need to do this in VB code behind inthe Master file I guess.
Question by:lrbrister
    LVL 32

    Expert Comment

    by:Daniel Wilson
    The best solution is a SQL Server cluster so that your app doesn't ahve to deal with this.  But ... doing this in the code-behind shouldn't be too hard -- as long as you're just trying to read.

    Somewhere ... maybe actually in a page from which your content pages inherit ... you could put a Connection property.

    This property would:
    * Instantiate a SqlConnection, if not already done
    * Attempt to connect to the primary DB server
    * If that fails, attempt to connect to the second DB server
    * Return the connection

    Think that will work for you?


    Author Comment

    Yes...that would work.  You have an example?
    LVL 32

    Accepted Solution

    Try something like this:

    you will need a module-level
    Private _GoodCon as SqlConnection

    Public ReadOnly Property GoodConnection() as SqlConnection
       if _GoodCon is nothing then
         set _GoodCon = new SqlConnection(ConnString1)
       end if
       if not TestCon(_GoodCon) then
         if _GoodCon.ConnectionString = ConnString1 then 
            _GoodCon.ConnectionString = ConnString2
            _GoodCon.ConnectionString = ConnString1
         if not TestCon(_GoodCon) then
           throw new exception ("Can't connect to either server!!!")
         end if
       end if
       return _GoodCon
     End Get
    End Property
    Private Function TestCon(C as SqlConnection) as Boolean
      dim cmd as new SqlCommand("Select 1", C)
       if C.State = Closed then
       end if
      catch ex as exception
       return false
      end try
      return true
    end function

    Open in new window


    Author Closing Comment

    Thanks.  This put me on the track I needed.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now