Connection String In Asp.Net When Database Mirroring Is Configured
In this tutorial i will let you know about how to configure Connection String In Asp.Net When Database Mirroring Is Configured.Database Mirroring which we are using for High availability and in my opinion it is better then Log-Shipping.
We already discussed about Database Mirroring and how to configure it in this post Configure Database Mirroring.Here are are using a connection string to connect to our Database which is on Default Instance(.).In case of failure what we have to do that our application will connect to our Failover Instance automatically.This is done in ADO.Net and Native SQL Client drivers itself.
Connection String:
1. With a Login that has been configured on both Instances.
<configuration> <system.web> <compilation debug="true" targetFramework="4.0"/> </system.web> <connectionStrings> <add name="con" connectionString="Data Source=.;Failover Partner=.\Instance1; User ID=sa; Password=high; Initial Catalog=testing"/> </connectionStrings> </configuration>
2. With Integrated Security.
<configuration> <system.web> <compilation debug="true" targetFramework="4.0"/> </system.web> <connectionStrings> <add name="con" connectionString="Data Source=.; Failover Partner=.\Instance1; Integrated Security=True; Initial Catalog=testing"/> </connectionStrings> </configuration>
In database mirroring the failover partner in the connection string is used as an alternate SQL Server if the initial connection to the principal SQL Server fails.If the initial connection to the principal SQL Server succeeds, then the failover SQL Server parameter will not be used. If not, then the failover partner should accept the connection and your users should be able to use the application as expected.