Friday, March 30, 2012
Mirroring confusion.
SP1
I am testing out Synchronous Mirroring and have a question about failover.
It seems the only way I can failover to the Mirror box is to log onto the
Principal box and hit the Failover button? Isn't the whole point of
mirroring to be able to handle the Principal not being available? Is there
another way? To clarify, I have no witness and am attempting a manual
failover.
TIA, ChrisRHi Chris,
I believe the option you are looking for is as follows from bol:
1.. Connect to the mirror server.
2.. Issue the following statement:
ALTER DATABASE <database_name> SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS
where <database_name> is the mirrored database.
The mirror server immediately transitions to principal server, and
mirroring is suspended.
Regards
Jamie
"ChrisR" <NotAChance@.ms.com> wrote in message
news:O9tTWmHyGHA.4232@.TK2MSFTNGP05.phx.gbl...
> SQL2K5
> SP1
> I am testing out Synchronous Mirroring and have a question about failover.
> It seems the only way I can failover to the Mirror box is to log onto the
> Principal box and hit the Failover button? Isn't the whole point of
> mirroring to be able to handle the Principal not being available? Is there
> another way? To clarify, I have no witness and am attempting a manual
> failover.
> TIA, ChrisR
>sql
Mirroring confusion.
TIA, ChrisRIn the event of a failure, the "witness" does that automagically.
-PatP|||Yes, but I am using "no witness" mirroring.|||You have to have a witness server to automatic failover.
The witness can be a stripped down server running SQL Server Express. It does not need to be a powerful platform or have a licensed install.|||Yes, but I am attempting a manual failover.
Mirroring confusion.
SP1
I am testing out Synchronous Mirroring and have a question about failover.
It seems the only way I can failover to the Mirror box is to log onto the
Principal box and hit the Failover button? Isn't the whole point of
mirroring to be able to handle the Principal not being available? Is there
another way? To clarify, I have no witness and am attempting a manual
failover.
TIA, ChrisRHi Chris,
I believe the option you are looking for is as follows from bol:
1.. Connect to the mirror server.
2.. Issue the following statement:
ALTER DATABASE <database_name> SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS
where <database_name> is the mirrored database.
The mirror server immediately transitions to principal server, and
mirroring is suspended.
Regards
Jamie
"ChrisR" <NotAChance@.ms.com> wrote in message
news:O9tTWmHyGHA.4232@.TK2MSFTNGP05.phx.gbl...
> SQL2K5
> SP1
> I am testing out Synchronous Mirroring and have a question about failover.
> It seems the only way I can failover to the Mirror box is to log onto the
> Principal box and hit the Failover button? Isn't the whole point of
> mirroring to be able to handle the Principal not being available? Is there
> another way? To clarify, I have no witness and am attempting a manual
> failover.
> TIA, ChrisR
>
Mirroring ASPState
Hello Does any one have any information on how to mirror the ASP.NET 2 ASPState database we have set the connection string to allow custom DB and failover partner but this is still not working.
Regards Matt.
Hi Matt,
Are you having problems with automatic failover not happening at all, or the ASP.NET connection does not get re-routed to the failover partner after auto-failover occurs?
Thanks,
Kaloian.
|||Hi Kaloian,
The problem that we are having is that the ASP.NET connection does not get re-routed to the failover partner after auto-failover. This is the connection string that i am using.
<sessionState mode="SQLServer"
sqlConnectionString="data source=Test; Failover Partner=Test2; initial catalog=Credit; user id=State;password=password"
cookieless="AutoDetect"
timeout="61"
allowCustomSqlDatabase="true" />
The databses all failover fine but it seems that the ASP.NET connection is never looking for the failover partner it just errors giving a named pipes error. But they are enabled on both the primary and the failover partner.
Thanks Matt.
|||I believe you are missing the Network parameter -->
Network=dbmssocn; for TCP/IP
so sqlConnectionString="data source=Test; Failover Partner=Test2; Network=dbmssocn; (etc)
Let us know if it works!
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/fd000cb1-9426-4ed9-8108-1907ddfd1c5f.htm
Mirroring ASPState
Hello Does any one have any information on how to mirror the ASP.NET 2 ASPState database we have set the connection string to allow custom DB and failover partner but this is still not working.
Regards Matt.
Hi Matt,
Are you having problems with automatic failover not happening at all, or the ASP.NET connection does not get re-routed to the failover partner after auto-failover occurs?
Thanks,
Kaloian.
|||Hi Kaloian,
The problem that we are having is that the ASP.NET connection does not get re-routed to the failover partner after auto-failover. This is the connection string that i am using.
<sessionState mode="SQLServer"
sqlConnectionString="data source=Test; Failover Partner=Test2; initial catalog=Credit; user id=State;password=password"
cookieless="AutoDetect"
timeout="61"
allowCustomSqlDatabase="true" />
The databses all failover fine but it seems that the ASP.NET connection is never looking for the failover partner it just errors giving a named pipes error. But they are enabled on both the primary and the failover partner.
Thanks Matt.
|||I believe you are missing the Network parameter -->
Network=dbmssocn; for TCP/IP
so sqlConnectionString="data source=Test; Failover Partner=Test2; Network=dbmssocn; (etc)
Let us know if it works!
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/fd000cb1-9426-4ed9-8108-1907ddfd1c5f.htm
sqlMirroring and Replication
I'm using replication and want to mirror my publisher to get high availability. As I understand the documentation the principal and the mirror must both use the same distributor instance. So if the distributor fails the replication fails. This seem like a big weakness. Maybe I'm missing some thing. Is there a way to set it up so that replication continues if a distributor fails -- some mechanism that will switch in a "back-up" distributor? I'm looking for a configuration that will continue to run in the event of any single failure. This means that both the publisher and the distributor must be covered by mechanisms that keeps them going in the event of a failure. Mirroring covers the failure of the publisher but I don't see a mechanism that will conver the failure of the distributor.
My application is developed in .net / c#. Data is accessed through .net sql server data provider etc.
The only solution right now is clustering, there's way too hard-coded server names at the publisher/distributor that makes it difficult to get mirroring to work. We're looking at developing other solutions, but they won't be available until after the next SQL Server release. But for now, clustering is your answer.
Mirroring and orphaned users
Hi there!
There is still a problem with mirrored (mapped) SQL Users. If you mirror a database where an application connects with an sql user, the mapping (login / user) will be lost on the mirror server. After a failover occurs, it it not possible to log onto the new principal database because the database use will be an orphaned user and has to be remapped to the login (using sp_change_users_login 'update_one', 'user', 'user').
Is there any chance to do it in a system trigger? What is the firing event after the failover occurs? I've tried something like following, but it doesn't fire.
alter TRIGGER map_orphaned_users
ON ALL SERVER
FOR ALTER_DATABASE
AS
execute sp_change_users_login 'update_one', 'easyris_41', 'easyris_41';
Someone an idea how to automate these usermapping after failover on the (new) principal server?
Based on:
http://www.microsoft.com/technet/prodtechnol/sql/2005/mirroringevents.mspx#EDBAC
you can be set up to be notified (or run a job or particular sp) when the server becomes the principal.
Thanks,
mark
|||Hmm, maybe thats a workaround.
But in my mind it doesn't confirm with the requirement of high availability with automatic failover. Furthermore, clients application could run into another exception (Login fails or something like that), what has to be adapted in applications what are designed for high avilibility.
Otherway all the stuff works with domain users. So it seems like a real bug. I can't see any conceptional reason for this behavior. Hope that will be fixed in SP2...
Torsten
|||OK, I am going to try to write a bit.
1. I completely agree that from a customer's point of view, if when using sql logins, if the database fails over and the clients cannot get to the database (for whatever reason. Here it is a mixed mapping from login on a different server to a user in a "new" database ), then the system is not "highly available." So, we haven't made it easy to use mirroring in certain scenarios. I may try to create a script that solves this problem this weekend.
2. On the other hand, this problem has been here at least since 7.0. In log shipping, backup/restore, and attach/detach this problem of moving the database to a different server where the meta data in master and msdb are different on different servers. The problem is that we have made moving a database to a different server so much easier that the problems that were small earlier are becoming bigger.
So, this really isn't a bug IMHO, but it is unexpected behavior (which is still bad from a customer's point of view).
Thanks,
Mark
|||I am just starting to look into mirroring and had run across this same problem. I have not had a chance to look into this but supposedly there is a task in SSIS that allows you to transfer logins from one server to another.|||
Hi guys,
I've asked MS about using sqlusers on a mirrored database and got this reply from Hugo Nunes, support Engineer at Microsoft.
In order to avoid orphaned users on the mirror database you’ll have to copy the logins corresponding to the database users, to the standby server. The copy must be made before restoring the database on the standby server. You’ll also need to copy the user with his SID. The Transfer Logins Task from SSIS performs that task for you as long you set the CopySids property to true.
It works.
|||
yes. but it doesn't solve the issue of default database for a login,
which leads to the same issue - login does not work.
|||Hi to All,
We are currently having issues like that before, the fix that we do is adding a short dynamic script that will remove orphaned user by executing sp_change_users_login 'update_one', '<user1>','<user1>' on the mirrored database everytime a switch occur.
hope this helps!
regards,
|||Hi Anders,
Did you ever got this to work? Do you know of any documents that walk you thought on how to do this? I am new with SSIS.
Thanks
Rick
|||Hi Rick,
Yes, it's been up and running for almost a year now.
Im sorry i dont have a walk through for you but the SSIS bit is pretty straight forward.
These documents should get you started.
Transfer Logins Task
http://msdn2.microsoft.com/en-us/library/ms137870.aspx
Set Task Properties
http://msdn2.microsoft.com/en-us/library/ms139733.aspx
/Anders
Mirroring and orphaned users
Hi there!
There is still a problem with mirrored (mapped) SQL Users. If you mirror a database where an application connects with an sql user, the mapping (login / user) will be lost on the mirror server. After a failover occurs, it it not possible to log onto the new principal database because the database use will be an orphaned user and has to be remapped to the login (using sp_change_users_login 'update_one', 'user', 'user').
Is there any chance to do it in a system trigger? What is the firing event after the failover occurs? I've tried something like following, but it doesn't fire.
alter TRIGGER map_orphaned_users
ON ALL SERVER
FOR ALTER_DATABASE
AS
execute sp_change_users_login 'update_one', 'easyris_41', 'easyris_41';
Someone an idea how to automate these usermapping after failover on the (new) principal server?
Based on:
http://www.microsoft.com/technet/prodtechnol/sql/2005/mirroringevents.mspx#EDBAC
you can be set up to be notified (or run a job or particular sp) when the server becomes the principal.
Thanks,
mark
|||Hmm, maybe thats a workaround.
But in my mind it doesn't confirm with the requirement of high availability with automatic failover. Furthermore, clients application could run into another exception (Login fails or something like that), what has to be adapted in applications what are designed for high avilibility.
Otherway all the stuff works with domain users. So it seems like a real bug. I can't see any conceptional reason for this behavior. Hope that will be fixed in SP2...
Torsten
|||OK, I am going to try to write a bit.
1. I completely agree that from a customer's point of view, if when using sql logins, if the database fails over and the clients cannot get to the database (for whatever reason. Here it is a mixed mapping from login on a different server to a user in a "new" database ), then the system is not "highly available." So, we haven't made it easy to use mirroring in certain scenarios. I may try to create a script that solves this problem this weekend.
2. On the other hand, this problem has been here at least since 7.0. In log shipping, backup/restore, and attach/detach this problem of moving the database to a different server where the meta data in master and msdb are different on different servers. The problem is that we have made moving a database to a different server so much easier that the problems that were small earlier are becoming bigger.
So, this really isn't a bug IMHO, but it is unexpected behavior (which is still bad from a customer's point of view).
Thanks,
Mark
|||I am just starting to look into mirroring and had run across this same problem. I have not had a chance to look into this but supposedly there is a task in SSIS that allows you to transfer logins from one server to another.|||
Hi guys,
I've asked MS about using sqlusers on a mirrored database and got this reply from Hugo Nunes, support Engineer at Microsoft.
In order to avoid orphaned users on the mirror database you’ll have to copy the logins corresponding to the database users, to the standby server. The copy must be made before restoring the database on the standby server. You’ll also need to copy the user with his SID. The Transfer Logins Task from SSIS performs that task for you as long you set the CopySids property to true.
It works.
|||
yes. but it doesn't solve the issue of default database for a login,
which leads to the same issue - login does not work.
|||Hi to All,
We are currently having issues like that before, the fix that we do is adding a short dynamic script that will remove orphaned user by executing sp_change_users_login 'update_one', '<user1>','<user1>' on the mirrored database everytime a switch occur.
hope this helps!
regards,
|||Hi Anders,
Did you ever got this to work? Do you know of any documents that walk you thought on how to do this? I am new with SSIS.
Thanks
Rick
|||Hi Rick,
Yes, it's been up and running for almost a year now.
Im sorry i dont have a walk through for you but the SSIS bit is pretty straight forward.
These documents should get you started.
Transfer Logins Task
http://msdn2.microsoft.com/en-us/library/ms137870.aspx
Set Task Properties
http://msdn2.microsoft.com/en-us/library/ms139733.aspx
/Anders
Mirroring and orphaned users
Hi there!
There is still a problem with mirrored (mapped) SQL Users. If you mirror a database where an application connects with an sql user, the mapping (login / user) will be lost on the mirror server. After a failover occurs, it it not possible to log onto the new principal database because the database use will be an orphaned user and has to be remapped to the login (using sp_change_users_login 'update_one', 'user', 'user').
Is there any chance to do it in a system trigger? What is the firing event after the failover occurs? I've tried something like following, but it doesn't fire.
alter TRIGGER map_orphaned_users
ON ALL SERVER
FOR ALTER_DATABASE
AS
execute sp_change_users_login 'update_one', 'easyris_41', 'easyris_41';
Someone an idea how to automate these usermapping after failover on the (new) principal server?
Based on:
http://www.microsoft.com/technet/prodtechnol/sql/2005/mirroringevents.mspx#EDBAC
you can be set up to be notified (or run a job or particular sp) when the server becomes the principal.
Thanks,
mark
|||Hmm, maybe thats a workaround.
But in my mind it doesn't confirm with the requirement of high availability with automatic failover. Furthermore, clients application could run into another exception (Login fails or something like that), what has to be adapted in applications what are designed for high avilibility.
Otherway all the stuff works with domain users. So it seems like a real bug. I can't see any conceptional reason for this behavior. Hope that will be fixed in SP2...
Torsten
|||OK, I am going to try to write a bit.
1. I completely agree that from a customer's point of view, if when using sql logins, if the database fails over and the clients cannot get to the database (for whatever reason. Here it is a mixed mapping from login on a different server to a user in a "new" database ), then the system is not "highly available." So, we haven't made it easy to use mirroring in certain scenarios. I may try to create a script that solves this problem this weekend.
2. On the other hand, this problem has been here at least since 7.0. In log shipping, backup/restore, and attach/detach this problem of moving the database to a different server where the meta data in master and msdb are different on different servers. The problem is that we have made moving a database to a different server so much easier that the problems that were small earlier are becoming bigger.
So, this really isn't a bug IMHO, but it is unexpected behavior (which is still bad from a customer's point of view).
Thanks,
Mark
|||I am just starting to look into mirroring and had run across this same problem. I have not had a chance to look into this but supposedly there is a task in SSIS that allows you to transfer logins from one server to another.|||
Hi guys,
I've asked MS about using sqlusers on a mirrored database and got this reply from Hugo Nunes, support Engineer at Microsoft.
In order to avoid orphaned users on the mirror database you’ll have to copy the logins corresponding to the database users, to the standby server. The copy must be made before restoring the database on the standby server. You’ll also need to copy the user with his SID. The Transfer Logins Task from SSIS performs that task for you as long you set the CopySids property to true.
It works.
|||
yes. but it doesn't solve the issue of default database for a login,
which leads to the same issue - login does not work.
|||Hi to All,
We are currently having issues like that before, the fix that we do is adding a short dynamic script that will remove orphaned user by executing sp_change_users_login 'update_one', '<user1>','<user1>' on the mirrored database everytime a switch occur.
hope this helps!
regards,
|||Hi Anders,
Did you ever got this to work? Do you know of any documents that walk you thought on how to do this? I am new with SSIS.
Thanks
Rick
|||Hi Rick,
Yes, it's been up and running for almost a year now.
Im sorry i dont have a walk through for you but the SSIS bit is pretty straight forward.
These documents should get you started.
Transfer Logins Task
http://msdn2.microsoft.com/en-us/library/ms137870.aspx
Set Task Properties
http://msdn2.microsoft.com/en-us/library/ms139733.aspx
/Anders
Mirroring and orphaned users
Hi there!
There is still a problem with mirrored (mapped) SQL Users. If you mirror a database where an application connects with an sql user, the mapping (login / user) will be lost on the mirror server. After a failover occurs, it it not possible to log onto the new principal database because the database use will be an orphaned user and has to be remapped to the login (using sp_change_users_login 'update_one', 'user', 'user').
Is there any chance to do it in a system trigger? What is the firing event after the failover occurs? I've tried something like following, but it doesn't fire.
alter TRIGGER map_orphaned_users
ON ALL SERVER
FOR ALTER_DATABASE
AS
execute sp_change_users_login 'update_one', 'easyris_41', 'easyris_41';
Someone an idea how to automate these usermapping after failover on the (new) principal server?
Based on:
http://www.microsoft.com/technet/prodtechnol/sql/2005/mirroringevents.mspx#EDBAC
you can be set up to be notified (or run a job or particular sp) when the server becomes the principal.
Thanks,
mark
|||Hmm, maybe thats a workaround.
But in my mind it doesn't confirm with the requirement of high availability with automatic failover. Furthermore, clients application could run into another exception (Login fails or something like that), what has to be adapted in applications what are designed for high avilibility.
Otherway all the stuff works with domain users. So it seems like a real bug. I can't see any conceptional reason for this behavior. Hope that will be fixed in SP2...
Torsten
|||OK, I am going to try to write a bit.
1. I completely agree that from a customer's point of view, if when using sql logins, if the database fails over and the clients cannot get to the database (for whatever reason. Here it is a mixed mapping from login on a different server to a user in a "new" database ), then the system is not "highly available." So, we haven't made it easy to use mirroring in certain scenarios. I may try to create a script that solves this problem this weekend.
2. On the other hand, this problem has been here at least since 7.0. In log shipping, backup/restore, and attach/detach this problem of moving the database to a different server where the meta data in master and msdb are different on different servers. The problem is that we have made moving a database to a different server so much easier that the problems that were small earlier are becoming bigger.
So, this really isn't a bug IMHO, but it is unexpected behavior (which is still bad from a customer's point of view).
Thanks,
Mark
|||I am just starting to look into mirroring and had run across this same problem. I have not had a chance to look into this but supposedly there is a task in SSIS that allows you to transfer logins from one server to another.|||
Hi guys,
I've asked MS about using sqlusers on a mirrored database and got this reply from Hugo Nunes, support Engineer at Microsoft.
In order to avoid orphaned users on the mirror database you’ll have to copy the logins corresponding to the database users, to the standby server. The copy must be made before restoring the database on the standby server. You’ll also need to copy the user with his SID. The Transfer Logins Task from SSIS performs that task for you as long you set the CopySids property to true.
It works.
|||
yes. but it doesn't solve the issue of default database for a login,
which leads to the same issue - login does not work.
|||Hi to All,
We are currently having issues like that before, the fix that we do is adding a short dynamic script that will remove orphaned user by executing sp_change_users_login 'update_one', '<user1>','<user1>' on the mirrored database everytime a switch occur.
hope this helps!
regards,
|||Hi Anders,
Did you ever got this to work? Do you know of any documents that walk you thought on how to do this? I am new with SSIS.
Thanks
Rick
|||Hi Rick,
Yes, it's been up and running for almost a year now.
Im sorry i dont have a walk through for you but the SSIS bit is pretty straight forward.
These documents should get you started.
Transfer Logins Task
http://msdn2.microsoft.com/en-us/library/ms137870.aspx
Set Task Properties
http://msdn2.microsoft.com/en-us/library/ms139733.aspx
/Anders
Mirroring and Logins
I've created some SSIS packages to move logins from the Primary server to the Mirror server. But I'm having a small glitch. Lets say I have a database dbA that's mirrored. I then add a login of some sort, say userA. userA's default database is dbA. When I add that login to the mirrored server, how do I get the default database to be dbA? Currently I'm getting the following error from Alter Login:
ALTER LOGIN [userA] WITH DEFAULT_DATABASE=[dbA]
Msg 954, Level 14, State 1, Line 1
The database "dbA" cannot be opened. It is acting as a mirror database. I'm currently adding the logins with master as the default and then using Alter to attempt setting it. I can mask the error with a TRY block, but if I fail over it seems I'm going to have an issue. Any thoughts on this would be greatly appreciated.
Thanks,
Larry
I think the mirrored DB is inaccessible (just think of it never existed)
The only way I can think of to change the default DB, is to actually break the mirror (or swap Primary/Mirror role = manual failover)
alter the default databases, then re-establish the mirror (swap the role again = manual failover back to original Primary/Mirror)
|||Thanks. I guess we'll have to implement a policy that we only add logins after hours or create a window of time for adding logins where we can take the database down a couple of times (to fail over and back). Seems a bit out there for a High Availability solution since it will increase downtime a lot compared to what we have now.
Thanks again,
Larry
sqlWednesday, March 28, 2012
Mirroring
I want build my own altert system, sending an SMS whenever a automatic
failover/failback happens.
Per Schjetne"Per Schjetne" <newsuser1@.gdconsult.no> wrote in message
news:%23V%23sM6caGHA.1196@.TK2MSFTNGP03.phx.gbl...
> Is there a way to detect if the principal or mirror is running the
> database? I want build my own altert system, sending an SMS whenever a
> automatic failover/failback happens.
You can set alerts on the messages in the event log. Talk to your monitoring
application vendor for more info.
Russ Kaufmann
MVP - Windows Server - Clustering
ClusterHelp.com, a Microsoft Certified Gold Partner
Web http://www.clusterhelp.com
Blog http://msmvps.com/clusterhelp|||select * from sys.database_mirroring
This posting is provided "AS IS" with no warranties, and confers no rights.
HTH,
~ Remus Rusanu
SQL Service Broker
http://msdn2.microsoft.com/en-us/library/ms166043(en-US,SQL.90).aspx
"Per Schjetne" <newsuser1@.gdconsult.no> wrote in message
news:%23V%23sM6caGHA.1196@.TK2MSFTNGP03.phx.gbl...
> Is there a way to detect if the principal or mirror is running the
> database? I want build my own altert system, sending an SMS whenever a
> automatic failover/failback happens.
> Per Schjetne
>|||The sys.dm_database_mirroring view will give you the state information that
you
need to monitor. You will need to access this on both partners.
Mike
http://www.solidqualitylearning.com
Disclaimer: This communication is an original work and represents my sole
views on the subject. It does not represent the views of any other person
or entity either by inference or direct reference.
"Per Schjetne" <newsuser1@.gdconsult.no> wrote in message
news:%23V%23sM6caGHA.1196@.TK2MSFTNGP03.phx.gbl...
> Is there a way to detect if the principal or mirror is running the
> database? I want build my own altert system, sending an SMS whenever a
> automatic failover/failback happens.
> Per Schjetne
>
Mirroring
I want build my own altert system, sending an SMS whenever a automatic
failover/failback happens.
Per Schjetne"Per Schjetne" <newsuser1@.gdconsult.no> wrote in message
news:%23V%23sM6caGHA.1196@.TK2MSFTNGP03.phx.gbl...
> Is there a way to detect if the principal or mirror is running the
> database? I want build my own altert system, sending an SMS whenever a
> automatic failover/failback happens.
You can set alerts on the messages in the event log. Talk to your monitoring
application vendor for more info.
--
Russ Kaufmann
MVP - Windows Server - Clustering
ClusterHelp.com, a Microsoft Certified Gold Partner
Web http://www.clusterhelp.com
Blog http://msmvps.com/clusterhelp|||select * from sys.database_mirroring
--
This posting is provided "AS IS" with no warranties, and confers no rights.
HTH,
~ Remus Rusanu
SQL Service Broker
http://msdn2.microsoft.com/en-us/library/ms166043(en-US,SQL.90).aspx
"Per Schjetne" <newsuser1@.gdconsult.no> wrote in message
news:%23V%23sM6caGHA.1196@.TK2MSFTNGP03.phx.gbl...
> Is there a way to detect if the principal or mirror is running the
> database? I want build my own altert system, sending an SMS whenever a
> automatic failover/failback happens.
> Per Schjetne
>|||The sys.dm_database_mirroring view will give you the state information that
you
need to monitor. You will need to access this on both partners.
--
Mike
http://www.solidqualitylearning.com
Disclaimer: This communication is an original work and represents my sole
views on the subject. It does not represent the views of any other person
or entity either by inference or direct reference.
"Per Schjetne" <newsuser1@.gdconsult.no> wrote in message
news:%23V%23sM6caGHA.1196@.TK2MSFTNGP03.phx.gbl...
> Is there a way to detect if the principal or mirror is running the
> database? I want build my own altert system, sending an SMS whenever a
> automatic failover/failback happens.
> Per Schjetne
>
Mirrored Records?
are duplicates in mirror image. Table has 2 columns, ColumnA and ColumnB.
Row1: ColumnA = x, ColumnB = y
Row2: ColumnA = y, ColumnB = x
Those 2 rows are exactly the same for me. Need a script that will delete
Row2 and all other rows where they're mirrored duplicates.
Thanks DarenDaren,
Once you do this, you should consider putting a constraint on the
table to enforce ColumnA <= ColumnB so this doesn't happen again.
It's a bad model if there are two ways of representing the same facts.
delete from T as T1
where ColumnA > ColumnB
and exists (
select * from T as T2
where T2.ColumnA = T1.ColumnB
and T2.ColumnB = T1.ColumnA
)
If you want to delete only these "mirror duplicates"
when they exist for the same customer/transaction/whatever,
you will need something like
delete from T as T1
where ColumnA > ColumnB
and exists (
select * from T as T2
where T2.customer = T1.customer
and T2.ColumnA = T1.ColumnB
and T2.ColumnB = T1.ColumnA
)
Steve Kass
Drew University
Daren Hawes wrote:
>Hi I need some SQL script help. Need script to delete all table rows that
>are duplicates in mirror image. Table has 2 columns, ColumnA and ColumnB.
>Row1: ColumnA = x, ColumnB = y
>Row2: ColumnA = y, ColumnB = x
>Those 2 rows are exactly the same for me. Need a script that will delete
>Row2 and all other rows where they're mirrored duplicates.
>Thanks Daren
>
>|||Thanks. I am a little
Do I need to create a new Table? I have added the actual names below.
Column a = FromID ; Column b = ToID
CREATE TABLE [dbo].[tbl_Matrix] (
[FareID] [int] IDENTITY (1, 1) NOT NULL ,
[FromID] [int] NULL ,
[ToID] [int] NULL ,
[PriceCode] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tbl_Matrix] ADD
CONSTRAINT [PK_tbl_Matrix] PRIMARY KEY CLUSTERED
(
[FareID]
) ON [PRIMARY]
GO
"Steve Kass" <skass@.drew.edu> wrote in message
news:%23eKPQBxZFHA.2212@.TK2MSFTNGP14.phx.gbl...
> Daren,
> Once you do this, you should consider putting a constraint on the
> table to enforce ColumnA <= ColumnB so this doesn't happen again.
> It's a bad model if there are two ways of representing the same facts.
> delete from T as T1
> where ColumnA > ColumnB
> and exists (
> select * from T as T2
> where T2.ColumnA = T1.ColumnB
> and T2.ColumnB = T1.ColumnA
> )
> If you want to delete only these "mirror duplicates"
> when they exist for the same customer/transaction/whatever,
> you will need something like
> delete from T as T1
> where ColumnA > ColumnB
> and exists (
> select * from T as T2
> where T2.customer = T1.customer
> and T2.ColumnA = T1.ColumnB
> and T2.ColumnB = T1.ColumnA
> )
> Steve Kass
> Drew University
>
> Daren Hawes wrote:
>|||Try the following untested DELETE statement:
DELETE FROM tbl_Matrix
WHERE EXISTS
(SELECT *
FROM tbl_Matrix AS T
WHERE T.fromid = tbl_Matrix.fromid
AND T.toid = tbl_Matrix.toid
AND T.fareid < tbl_Matrix.fareid)
Now make FromID and ToID not nullable and add a unqiue constraint on those
two columns.
David Portas
SQL Server MVP
--|||Thanks for the reply Dave (I'm working with Daren),
Tryed that 1, deleted nothing, modified it to this...
DELETE FROM tbl_Matrix
WHERE EXISTS
(SELECT *
FROM tbl_Matrix AS T
WHERE T.fromid = tbl_Matrix.toid
AND T.toid = tbl_Matrix.fromid)
...and it deleted everything.
This is a copy of the script we've used to create the table's data, perhaps
if we wrote this script a bit better, wouldn't need another script to clean
it up...
declare @.Counter int
declare @.Counter2 int
select @.Counter=1
select @.Counter2=1
while @.Counter < 136
begin
while @.Counter2 < 136
Begin
Insert into dbo.tbl_Matrix (FromID,ToID)
Values (@.Counter,@.Counter2)
set @.Counter2 = @.Counter2 + 1
End
set @.Counter = @.Counter + 1
set @.Counter2 = 1
end
Regards,
Offal Eater
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:xZ6dndpRhvr8_gPfRVn-sw@.giganews.com...
> Try the following untested DELETE statement:
> DELETE FROM tbl_Matrix
> WHERE EXISTS
> (SELECT *
> FROM tbl_Matrix AS T
> WHERE T.fromid = tbl_Matrix.fromid
> AND T.toid = tbl_Matrix.toid
> AND T.fareid < tbl_Matrix.fareid)
> Now make FromID and ToID not nullable and add a unqiue constraint on those
> two columns.
> --
> David Portas
> SQL Server MVP
> --
>|||Thanks for the reply Dave (I'm working with Daren),
Not having any luck with these scripts, I've included the script we've used
to create the table. Perhaps if we wrote this differently, wouldn't have
need for the 'clean-up' script.
declare @.Counter int
declare @.Counter2 int
select @.Counter=1
select @.Counter2=1
while @.Counter < 136
begin
while @.Counter2 < 136
Begin
Insert into dbo.tbl_Matrix (FromID,ToID)
Values (@.Counter,@.Counter2)
set @.Counter2 = @.Counter2 + 1
End
set @.Counter = @.Counter + 1
set @.Counter2 = 1
end
Any feedback would be great.
Thx,
Offal Eater
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:xZ6dndpRhvr8_gPfRVn-sw@.giganews.com...
> Try the following untested DELETE statement:
> DELETE FROM tbl_Matrix
> WHERE EXISTS
> (SELECT *
> FROM tbl_Matrix AS T
> WHERE T.fromid = tbl_Matrix.fromid
> AND T.toid = tbl_Matrix.toid
> AND T.fareid < tbl_Matrix.fareid)
> Now make FromID and ToID not nullable and add a unqiue constraint on those
> two columns.
> --
> David Portas
> SQL Server MVP
> --
>|||T1 and T2 are table aliases. You need to compare each
row of T with the rest of T, and to distinguish the "this row"
table and the "rest of" table, you need the aliases:
Since FareID is the primary key, this will do
delete from tbl_Matrix as T1
where ToID > FromID
and exists (
select * from tbl_Matrix as T2
where T2.FromID = T1.ToID
and T2.ToID = T1.FromID
)
This will arbitrarily remove the one of the two mirror duplicates
for which ToID < FromID. If you want to remove, say, the
one with the smaller FareID, you could do this instead:
delete from tbl_Matrix as T1
where exists (
select * from tbl_Matrix as T2
where T2.FromID = T1.ToID
and T2.ToID = T1.FromID
and T2.FareID > T1.FareID
)
Seeing your table now, I'd recommend you change the primary
key to (FromID, ToID), and add a table constraint to enforce
FromID < ToID, or at least put a UNIQUE constraint on
(FromID, ToID), and make those two columns NOT NULL (if
not all columns). I don't see much use to the column FareID,
actually, but removing it might mess up other thing you rely on.
There could be other problems, too. You could have many rows
with the same FromID, ToID pair in the same order, but with
different FareID values. So you might want to do this:
delete from tbl_Matrix as T1
where exists (
select * from tbl_Matrix as T2
where (
T2.FromID = T1.ToID
and T2.ToID = T1.FromID
) or (
T2.FromID = T1.FromID
and T2.ToID = T1.ToID
)
and T2.FareID > T1.FareID
)
If you have rows where FromID = ToID, you can delete them
separately. I assume those would make no sense, but you have
nothing to prevent that from occurring right now.
SK
Daren Hawes wrote:
>Thanks. I am a little
>Do I need to create a new Table? I have added the actual names below.
>Column a = FromID ; Column b = ToID
>CREATE TABLE [dbo].[tbl_Matrix] (
> [FareID] [int] IDENTITY (1, 1) NOT NULL ,
> [FromID] [int] NULL ,
> [ToID] [int] NULL ,
> [PriceCode] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL
> ) ON [PRIMARY]
>GO
>ALTER TABLE [dbo].[tbl_Matrix] ADD
> CONSTRAINT [PK_tbl_Matrix] PRIMARY KEY CLUSTERED
> (
> [FareID]
> ) ON [PRIMARY]
>GO
>
>"Steve Kass" <skass@.drew.edu> wrote in message
>news:%23eKPQBxZFHA.2212@.TK2MSFTNGP14.phx.gbl...
>
>
>|||> Tryed that 1, deleted nothing, modified it to this...
I ran your script and it didn't generate any duplicates so there is nothing
to delete - the combination of (FromID, ToID) is already unique (18225
rows). If you have something different in your data then please post a few
INSERT statements to generate some sample data that we can use to test it
out.
> This is a copy of the script we've used to create the table's data,
> perhaps if we wrote this script a bit better, wouldn't need another script
> to clean it up...
I posted a different solution to this in reply to Daren's post earlier
today.
David Portas
SQL Server MVP
--|||Here's a much better way to create the table. It uses
just one insert and no loops, and has much less chance of
off-by-one errors:
-- create a temporary table full of integers
declare @.Ints table (
IntVal int primary key
)
insert into @.Ints
select OrderID-10247
from Northwind..Orders
where OrderID-10247 between 1 and 136
-- Insert everything at once:
insert into dbo.tbl_Matrix(FromID, ToID)
select N1.IntVal, N2.IntVal
from @.Ints as N1 join @.Ints as N2
on N1.IntVal between 1 and 136
and N2.IntVal between N1.IntVal and 136
-- or N2.IntVal between N1.IntVal+1 and 136
If you want loops, but no mirror duplicates, replace
set @.Counter2 = 1
with
set @.Counter2 = @.Counter
This will continue to give you rows where FromID = ToID. If you don't
want those, start @.Counter2 one higher. Here's a guess, cleaned up
a bit, but I'd never trust this as much as the first suggestion I gave.
declare @.Counter int
declare @.Counter2 int
select @.Counter=0
while @.Counter < 135
begin
set @.Counter = @.Counter + 1
set @.Counter2 = @.Counter
while @.Counter2 < 135
Begin
set @.Counter2 = @.Counter2 + 1
Insert into dbo.tbl_Matrix (FromID,ToID)
Values (@.Counter,@.Counter2)
End
end
SK
Offal Eater wrote:
>Thanks for the reply Dave (I'm working with Daren),
>Not having any luck with these scripts, I've included the script we've used
>to create the table. Perhaps if we wrote this differently, wouldn't have
>need for the 'clean-up' script.
>declare @.Counter int
>declare @.Counter2 int
>select @.Counter=1
>select @.Counter2=1
>while @.Counter < 136
>begin
> while @.Counter2 < 136
> Begin
> Insert into dbo.tbl_Matrix (FromID,ToID)
> Values (@.Counter,@.Counter2)
> set @.Counter2 = @.Counter2 + 1
> End
>set @.Counter = @.Counter + 1
>set @.Counter2 = 1
>end
>Any feedback would be great.
>Thx,
>Offal Eater
>"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
>news:xZ6dndpRhvr8_gPfRVn-sw@.giganews.com...
>
>
>|||David,
I don't think the OP wants both (a, b) and (b, a). The 18225 rows
from the script are all (a,b) where a and b are between 1 and 135.
One way to eliminate the "mirror duplicates" is to generate only pairs
where a <= b (or perhaps a < b). There should be either 9180 or
9045 rows, depending on whether = is included.
SK
David Portas wrote:
>I ran your script and it didn't generate any duplicates so there is nothing
>to delete - the combination of (FromID, ToID) is already unique (18225
>rows). If you have something different in your data then please post a few
>INSERT statements to generate some sample data that we can use to test it
>out.
>
>
>I posted a different solution to this in reply to Daren's post earlier
>today.
>
>
Mirrored linked server failover.
Andre,
You can specify the partner name in the linked server server properties and the linked server will automatically failover from the principal to the mirror if the principal is failed over.
Regards,
Matt Hollingswort
Sr. Program Manager
Microsoft SQL Server
sqlMirrored linked server failover.
Andre,
You can specify the partner name in the linked server server properties and the linked server will automatically failover from the principal to the mirror if the principal is failed over.
Regards,
Matt Hollingswort
Sr. Program Manager
Microsoft SQL Server
Mirror Status Change
changes from Principal to Mirrored?
Also, can I determine who or what caused the status to change?
Hi
SELECT * FROM sys.database_mirroring;
"BigSam" <BigSam@.discussions.microsoft.com> wrote in message
news:49F51B2A-1AA4-4BF5-ADC4-2C5C2E629FB4@.microsoft.com...
> How can I determine when the status of a mirrored database on a server
> changes from Principal to Mirrored?
> Also, can I determine who or what caused the status to change?
|||This shows the current status, but not who, what, when, how, or why it changed.
"Uri Dimant" wrote:
> Hi
> SELECT * FROM sys.database_mirroring;
>
> "BigSam" <BigSam@.discussions.microsoft.com> wrote in message
> news:49F51B2A-1AA4-4BF5-ADC4-2C5C2E629FB4@.microsoft.com...
>
>
|||You can see information about the database mirroring state change in the
error log.
Database mirroring is active with database 'Database1' as the principal copy.
Database mirroring is active with database 'Database1' as the mirror copy.
Another option is to capture the Database Mirroring State Change Event Class
with SQL Trace or Event Notifications.
http://msdn2.microsoft.com/en-us/library/ms191502.aspx
Ola Hallengren
http://ola.hallengren.com
"BigSam" wrote:
[vbcol=seagreen]
> This shows the current status, but not who, what, when, how, or why it changed.
> "Uri Dimant" wrote:
Mirror Status Change
changes from Principal to Mirrored?
Also, can I determine who or what caused the status to change?Hi
SELECT * FROM sys.database_mirroring;
"BigSam" <BigSam@.discussions.microsoft.com> wrote in message
news:49F51B2A-1AA4-4BF5-ADC4-2C5C2E629FB4@.microsoft.com...
> How can I determine when the status of a mirrored database on a server
> changes from Principal to Mirrored?
> Also, can I determine who or what caused the status to change?|||This shows the current status, but not who, what, when, how, or why it changed.
"Uri Dimant" wrote:
> Hi
> SELECT * FROM sys.database_mirroring;
>
> "BigSam" <BigSam@.discussions.microsoft.com> wrote in message
> news:49F51B2A-1AA4-4BF5-ADC4-2C5C2E629FB4@.microsoft.com...
> > How can I determine when the status of a mirrored database on a server
> > changes from Principal to Mirrored?
> > Also, can I determine who or what caused the status to change?
>
>|||You can see information about the database mirroring state change in the
error log.
Database mirroring is active with database 'Database1' as the principal copy.
Database mirroring is active with database 'Database1' as the mirror copy.
Another option is to capture the Database Mirroring State Change Event Class
with SQL Trace or Event Notifications.
http://msdn2.microsoft.com/en-us/library/ms191502.aspx
Ola Hallengren
http://ola.hallengren.com
"BigSam" wrote:
> This shows the current status, but not who, what, when, how, or why it changed.
> "Uri Dimant" wrote:
> > Hi
> >
> > SELECT * FROM sys.database_mirroring;
> >
> >
> >
> > "BigSam" <BigSam@.discussions.microsoft.com> wrote in message
> > news:49F51B2A-1AA4-4BF5-ADC4-2C5C2E629FB4@.microsoft.com...
> > > How can I determine when the status of a mirrored database on a server
> > > changes from Principal to Mirrored?
> > > Also, can I determine who or what caused the status to change?
> >
> >
> >sql
Mirror Status
d
servers is active ?Is this a database mirroring question? Mirroring is at the database level.
Try
select * from sys.database_mirroring
and look for mirroring_role and mirroring_role_desc. They should say
PRINCIPAL or MIRROR.
Hope this helps,
Ben Nevarez, MCDBA, OCP
Database Administrator
"PJU" wrote:
> Are there Stored Procedures or tables that will tell me which of the mirro
red
> servers is active ?
>
Mirror Status
servers is active ?Is this a database mirroring question? Mirroring is at the database level.
Try
select * from sys.database_mirroring
and look for mirroring_role and mirroring_role_desc. They should say
PRINCIPAL or MIRROR.
Hope this helps,
Ben Nevarez, MCDBA, OCP
Database Administrator
"PJU" wrote:
> Are there Stored Procedures or tables that will tell me which of the mirrored
> servers is active ?
>