0

I have an ASP.NET site using LINQ to SQL set up with multiple databases (by changing the Source for the tables on the other/"secondary" server). As seen here.

How do I set up a Failover Partner for this? I have it set up in the connection string, but I had to hardcode the Source with the server name, so that doesn't work.

Community
  • 1
  • 1
Marcus
  • 5,407
  • 3
  • 31
  • 54

1 Answers1

0

The best method I could find/come up with was to create two LINQ External Mappings. On startup, I check to see if the main server is running using the main Mapping. If it's not, I set my connections to use the second LINQ mapping that has the FailOver database:

var xmlPath = @"C:\myAppFailOver.map";
System.Data.Linq.Mapping.XmlMappingSource linqMapping = System.Data.Linq.Mapping.XmlMappingSource.FromReader(System.Xml.XmlReader.Create(xmlPath));
using (DataClassesDataContext db = new DataClassesDataContext(connString, linqMapping))
{
    //code
}
Marcus
  • 5,407
  • 3
  • 31
  • 54