Showing posts with label smo. Show all posts
Showing posts with label smo. Show all posts

Monday, March 26, 2012

How to determine mirroring role?

Once I have identitied that mirroring is enabled on database via SMO Database.IsMirroringEnabled, I need to determine the mirroring role. I noticed an enumerated type - MirroringRole, but no SMO method/property to access it.

I have tried to query the sys.database_mirroring table directly, but this fails with an exception on the mirror database - as it is being mirrorred :-(

What is the recommended way to determine the mirroring role?

Thanks, Nick

You might try in calling from a C# embedded in SMO, like converting the value from c# to smo.|||

Not sure what you mean, I have tried querying the database ...

String query = String.Format("SELECT mirroring_role FROM sys.database_mirroring WHERE mirroring_guid = '{0}'", db.MirroringID.ToString());

DataSet dsResultSet = db.ExecuteWithResults(query);

.. but this causes an exception as the database is being mirrored.

+ base {"Execute with results failed for Database 'Mms'. "} Microsoft.SqlServer.Management.Smo.SmoException {Microsoft.SqlServer.Management.Smo.FailedOperationException}
+ InnerException {"The database \"Mms\" cannot be opened. It is acting as a mirror database."} System.Exception {System.Data.SqlClient.SqlException}

Thanks, Nick

|||

You don't need to connect to the mirror database (you can't, as you have experienced). You can connect to the master database on the mirror server and execute the following query:

SELECT m.mirroring_role_desc
FROM sys.database_mirroring m JOIN sys.databases d
ON m.database_id = d.database_id
WHERE d.name = '<your_database_name_here>'

How to determine mirroring role?

Once I have identitied that mirroring is enabled on database via SMO Database.IsMirroringEnabled, I need to determine the mirroring role. I noticed an enumerated type - MirroringRole, but no SMO method/property to access it.

I have tried to query the sys.database_mirroring table directly, but this fails with an exception on the mirror database - as it is being mirrorred :-(

What is the recommended way to determine the mirroring role?

Thanks, Nick

You might try in calling from a C# embedded in SMO, like converting the value from c# to smo.|||

Not sure what you mean, I have tried querying the database ...

String query = String.Format("SELECT mirroring_role FROM sys.database_mirroring WHERE mirroring_guid = '{0}'", db.MirroringID.ToString());

DataSet dsResultSet = db.ExecuteWithResults(query);

.. but this causes an exception as the database is being mirrored.

+ base {"Execute with results failed for Database 'Mms'. "} Microsoft.SqlServer.Management.Smo.SmoException {Microsoft.SqlServer.Management.Smo.FailedOperationException}
+ InnerException {"The database \"Mms\" cannot be opened. It is acting as a mirror database."} System.Exception {System.Data.SqlClient.SqlException}

Thanks, Nick

|||

You don't need to connect to the mirror database (you can't, as you have experienced). You can connect to the master database on the mirror server and execute the following query:

SELECT m.mirroring_role_desc
FROM sys.database_mirroring m JOIN sys.databases d
ON m.database_id = d.database_id
WHERE d.name = '<your_database_name_here>'

Wednesday, March 21, 2012

How to detect whether SMO is installed?

Hi, folks --
I am working on an install bootstrapper that (among other things)
will install Server Management Objects (SQLServer2005_XMO.msi from SQL
Server 2005 Feature Pack) iff it's not already installed.
So, how to detect programmatically whether or not it's already
installed?
What files/version/registry keys/usual suspects should I be looking
for?
Thanks in advance for your help.
-- Davidson
Hello n7dai@.comcast.net,
I normally look for C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies\Microsoft.SqlServer.Smo.d ll.
I believe current-most is 9.0.3042.0.
Thanks!
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
|||What about:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=577731&SiteID=1
Jens K. Suessmeyer.
http://www.sqlserver2005.de
<n7dai@.comcast.net> wrote in message
news:1175273193.753957.182290@.e65g2000hsc.googlegr oups.com...
> Hi, folks --
> I am working on an install bootstrapper that (among other things)
> will install Server Management Objects (SQLServer2005_XMO.msi from SQL
> Server 2005 Feature Pack) iff it's not already installed.
> So, how to detect programmatically whether or not it's already
> installed?
> What files/version/registry keys/usual suspects should I be looking
> for?
> Thanks in advance for your help.
> -- Davidson
>