Consulting / code examples on how to make a Cluster Aware application

I looked at web resources on how to make a Cluster Aware application / web application using the failover cluster API . I found many technical articles, but not one of them was written from the point of view of a programmer. Does anyone have any good links or can provide me with code samples or some other input on how to make a Cluster Aware application from a programmerโ€™s point of view? We use C # as our main programming language.

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

Since I did not find anything, I suspect that something is missing!

Vg

Ausgar

+4
source share
2 answers

What a score?

Am I following the same information?

In a scenario in which an application has a database residing in an SQL cluster. When the cluster crashes, the SQL connection pool becomes invalid and corrupted. The connection pool must be cleared and re-created without throwing an exception.

From a code point of view, you need to first.

  • Send the SQL query to the connection pool.
  • Catching an exception to use an invalid SQL connection pool.
  • Empty the connection pool or iterate through all the connections until the pool receives the connection.
  • Restore a new connection pool.
  • Resubmit the SQL query.

My problem is that I am an infrastructure architect, and my coding skills are weak in the best of times.

+1
source

Playing and with the help of colleagues came 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
source

Source: https://habr.com/ru/post/1302112/


All Articles