How to get connection string of a database mirroring?

I want to write to program to connect to a database mirroring, and now I'm confused with the connection string. My database mirroring was installed on three SQL Server instances on three virtual PCs. I want my program to run on one of them and connect to the database. The database will be switched roles (principal becomes mirror, and vice-versa).

I know 2 connection strings, but I really doubt that there are some better solutions. Some solution to configure the database, so I don't have to switch the connection strings. In other words, the connection to database mirroring is transparent to the client. Clients don't know about the database mirroring, they just want to know the connection string. How can I do that?

Thank you very much to your help.


Solution 1:

You must add the FailoverPartner to the connection string. And, as usual, there is an example on www.connectionstrings.com:

Data Source=myServerAddress; Failover Partner=myMirrorServerAddress; Initial Catalog=myDataBase; Integrated Security=True;

Whenever you find yourself asking something about a connection string, just use the dedicated class SqlConnectionStringBuilder.