views:

26

answers:

2

I have setup Database mirroring for SQL Server 2005 for my database on two different SQL Server machines. There is no witness server used here. I also see the status "Principal/Synchronized" and "Mirror,Synchronized/Restoring" respectively on Primary and Mirror servers for my database.

Now I wanted to test whether the failover to mirror server works fine or not. So I wrote a small console app like below.

try
{
    SqlConnection cn = new SqlConnection("data source=PRIMARYSQL1;Failover Partner=MIRRORSQL1;initial catalog=TESTDB;Integrated Security=SSPI;");
    SqlCommand cm = new SqlCommand("insert into department(name) values('Dept10')", cn);
    cn.Open();
    cm.ExecuteNonQuery();
}

I then turned off thehSQL Server and SQL Agent services on the primary server and I expected my console app to still work fine but I get below error.

"A network-related or instance-specific error occurred while establishing a conne ction to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a conne ction to SQL Server)"

Also, once the primary server goes down I have no way to make the mirror database primary as it doesn't allow me to do that from the mirror server.

I am sure I am doing something wrong. Can anyone help me?

A: 

I think you're looking for something like this (run this on the mirror):

ALTER DATABASE dbName SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS GO

RQDQ
After doing this,Do I still need to change my connectionstring or I should expect the original connectionstring it to work automatically? Actually After performing the alter database query my code still didn't wori with "data source=PRIMARYSQL1;Failover Partner=MIRRORSQL1;initial catalog=TESTDB;Integrated Security=SSPI;" and I had to change the connectionstring to "data source=MIRRORSQL1;Failover Partner=PRIMARYSQL1;initial catalog=TESTDB;Integrated Security=SSPI;" to make it work. That's wrong isn't it?
MICHAEL
Interesting... I did my testing with SQL Server 2008 and focused on having a witness server. You'll probably have to dig through the docs on MSDN to get to this level of nitty-gritty (that's what I had to do back in the day).
RQDQ
A: 

You are expecting automatic failover to occur, but automatic failover cannot occur w/o a witness. Given that any SQL Express instance running from any cheap/aging hardware can act as a witness, I would strongly suggest that you add a witness and have automatic failover, rather than have to do manual failover with potential data loss in case of a primary loss.

Remus Rusanu
ok so I added the sqlexpress as a witness and then tried to test the automatic failover and it worked fine. The only question that I have now is when my original principal came back online it didn't become the primary automatically and I had to do the failover on the mirror explicitly.Here are my steps.1. turn off sql server service on primary sonow the witness made my mirror as the primary and my code worked fine 2. I started the sql server service back again on the original primary and was expecting that it will become the primary again and that didn't happen. Is my expectation right here?
MICHAEL
No. Once failover occurs, the old mirror becomes the principal and the old principal becomes the mirror. If the old principal starts back, it will start as the new role (mirror), not as the old role (principal). Unlike failover clustering, in mirroring there is no concept of a 'favourite' host.
Remus Rusanu