Microsoft has enhanced the client connection
capabilities to become mirroring aware. In other words, a client
application is now able to connect to either partner in a mirrored
configuration. The client would, of course, be connecting only to the
server instance that is the current principal. With the help of an
extension to the client connection configuration file, all .NET
applications can easily add both partners to their connection string
information, and when a principal fails, they can automatically
establish a connection to the new principal (in a mirrored
configuration). Figure 1 shows the added connection string information that you provide in the configuration file (app.config) for your application. This enhancement uses the Failover Partner= addition that identifies the proper failover server instance for this mirrored configuration.
As a bonus, we have
provided a small .NET C# client application that you can easily use to
test client connections in a database mirroring configuration. With Visual Studio, you just open the WindowsApplication4.sln file (solution file), and the entire application comes up in Visual Studio. Figure 2 shows this simple application in Visual Studio.
This simple test program displays data from the Product table in the AdventureWorks
database (which you are mirroring), along with the exact date and time
of the data retrieval, the name of the server instance the data came
from, and the SQL process ID (SPID) of the current server instance. This
way, you can easily see which physical server the data is coming from.
If you are trying to use this program, all you have to do is update the app.config file connection string entry with your two partner server instance names (REM12374333\SQL08DE01 and REM12374333\SQL08DE02, in this example):
ConnectionString=
"Server= REM12374333\SQL08DE01;
Failover Partner= REM12374333\SQL08DE02;
Database=AdventureWorks;...."
Then you execute the test application. This application automatically connects to the current principal database (AdventureWorks on the REM12374333\SQL08DE01 server instance, in this example), as you can see in Figure 3.
Next, you can fail over the
principal to the mirror server, using the Database Properties Mirroring
page’s Failover button .
After you have failed this server over to its mirror (that is, switched
roles), you simply click the Retrieve button at the bottom of the
client test program to access the data in the AdventureWorks database again. Figure 4
shows this subsequent data retrieval. The test application shows the
same data rows, along with the date and time of this data retrieval and
the name of the server instance from which it got its data.
In this case, the data came from the other partner server instance (AdventureWorks on the REM12374333\SQL08DE02
server instance, in this example). The test application simply uses the
added connection information to reestablish its connection to the
failed-over server instance (that is, the mirror server), completely
transparently to the application.