开发者

Advise/Code samples on how to make an application "Cluster Aware" [closed]

开发者_如何转开发 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago.

I've browsed the web for resources regarding how to make an application/web application "Cluster Aware" using the Failover Cluster API. I found a lot of technical articles but none written from the programmer perspective. Does someone have any good links or can provide me with code samples or some other input on how to make an application Cluster Aware from a programmer point of view? We use C# as our primary programming language.

The cluster is an active/passive cluster containing two nodes (Windows 2003 Server) running IIS.

Since I haven´t found anything I suspect that I am missing something!

Br

Ausgar


Did you have any luck around this?

I am chasing the same information?

In the scenario where an application has a database residing on a SQL cluster. When the cluster performs a fail-over the SQL connection pool becomes invalid and corrupt. The connection pool needs to be flushed and re-created without surfacing the exception.

From a code point of view you need to first.

  1. Submit a SQL query to the connection pool.
  2. Capture the exception from the use of an invalid SQL connection pool.
  3. Flush the connection pool or iterate through all the connections until the pool has no connection avail.
  4. Re-create a new connection pool.
  5. Re-submit the SQL query.

My problem is that I am a Infrastructure Architect and my coding skills are weak at the best of times.


Been playing and with the help of a collegue have come up with the following as an example.

static void Main(string[] args)
    {
        Boolean PrevSqlError = false;
        Boolean NewSqlPool = false;
        String ConStr = "Data Source=SQL-CLUSTER1;Initial Catalog=Example;Integrated Security=True;Connection Timeout=60;Min pool size=5";
        Console.WriteLine("Press any key to read from database");
        Console.ReadKey();
        while (true)
        {
            try
            {
                Console.WriteLine("Attempting to connect");

                using (var context1 = new ExampleDataContext())
                {
                    var customers1 = context1.Customers.ToList();
                    var connection1 = new SqlConnection(ConStr);
                    connection1.Open();
                    PrintCustomers(customers1);
                    connection1.Close();
                }
                PrevSqlError = false;
                NewSqlPool = false;
                Console.WriteLine("Sleeping 3s");
                Thread.Sleep(3000);
            }
            catch (SqlException sqlException)
            {
                var SqlError = sqlException.Number;
                Console.WriteLine("Error connecting to SQL : " + SqlError+" : "+sqlException.Message);
                if (NewSqlPool == true)
                {
                    Console.WriteLine("Error in New Connection Pool. Exiting!");
                    Thread.Sleep(10000);
                    return;
                }
                if (PrevSqlError == true)
                {
                    if (SqlError == 10054 || SqlError == 232 || SqlError == 233 || SqlError == 64 || SqlError == 4060)
                    {
                        Console.WriteLine("SQL Cluster Failing Over. Waiting 5s");
                        SqlConnection.ClearAllPools();
                        PrevSqlError = false;
                        NewSqlPool = true;
                        Thread.Sleep(5000);
                    }
                    else
                    {
                        Console.WriteLine("Fatal SQL Exception. Exiting!");
                        Thread.Sleep(10000);
                        return;
                    }
                }
                else
                {
                Console.WriteLine("SQL Error, Retrying in 3s");
                PrevSqlError = true;
                Thread.Sleep(3000);
                }
            }
        }
    }

    private static void PrintCustomers(List<Customer> customers)
    {
        foreach (var item in customers)
        {
            Console.WriteLine(string.Format("{0} - {1}", item.Id, item.Name));
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜