About the author

Steven HarmanSteven Harman is a passionate developer who believes that writing great software isn't just a job, its a craft.

ASP.NET MVP

For recent posts and more about me, scroll to the bottom.

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

Jobs

Badges

  • Subtext Project
  • Support Subtext
  • HiddenNetwork.com Banner

Using SQL-DMO in your .NET app... mine's broken!

"SQL Distributed Management Objects (SQL-DMO) is a collection of objects encapsulating Microsoft® SQL Server™ database and replication management." Well pretty much sums it up for me!

But in all honesty, SQL-DMO is a great tool that you can use for accessing and manipulating your SQL Server DB's from within your .NET applications. One such application [here comes the obligatory plug] is subText! We are currently using SQL-DMO in a custom database connection string builder that we use to get information about local (or network) SQL Servers while installing the subText platform. This allows us to have a quazi-wizard method for building the db connection string, and we hope that will equate to a better user experience.

As usual, I'm starting off on a tangent... so what I'm driving at here is that last week when I updated my local codebase to the latest subText bits, along with it came Simo's work on the connection string builder it's use of SQL-DMO. So, like always I fired up VS.NET, and built the solution with the new codeset. And what did I see? Build Errors! The cause was an unresolved assembly SQLDMO. The issue... I didn't have SQL-DMO (which is part of SQL Server, SQL Server client tools, and MSDE... none of which were installed on my development box. My SQL Sever sits on another box on my local network, and any apps I'm working on on my dev box just point to it. Then, just for kicks, I tried to run some subText assemblies that were compiled on a machine that did have SQL-DMO installed. What happened? This:

System.Runtime.InteropServices.COMException: COM object with CLSID {10020100-E260-11CF-AE68-00AA004A34D5} is either not valid or not registered.
So, you need to have the SQLDMO COM installed on what ever box it is that you're attempting to run the code utilizing SQL-DMO on. I didn't want to install SQL Server nor MSDE on my dev box, just the Client Tools... so I followed these instructions. One thing to pay attention to when installing is the Select Components dialog box. As you can see to the above, you need to be sure to select the Headers and Libraries option. Also, in order to install database components from a network share, you must first do one of the following:
  1. Map the network share containing the extracted service pack files to an available drive letter on the local computer, navigate to the folder on the mapped drive that contains Setup.bat, and then run Setup.bat.
  2. Start Setup by running the Setupsql.exe file found in \X86\Setup, which is a subfolder of the folder on the network share that contains the extracted service pack files.
This is what will actually install and register the SQLDMO.dll as needed.

Unfortunately, you're not done yet. When I re-compiled and ran my code on my dev box (hoping for the best) I got the following:

System.InvalidCastException: QueryInterface for interface SQLDMO.NameList failed.
A quick Google search revealed that I needed to install SQL Server SP2 or greater to fix this issue. So, after installing SP4, I again rebuilt subText and tried to run the connection string builder. SUCCESS!

What others are saying.

# re: Using SQL-DMO in your .NET app... mine's broken!
Gravatar Haacked
Jan 07, 2006
Hmmm... This could be problematic. We can't assume that everyone's hosting is going to have these com libraries registered and installed properly. We may have to abandon these plans.... I'll send an email out...
# re: Using SQL-DMO in your .NET app... mine's broken!
Gravatar Steve Harman
Jan 07, 2006
Phil, I agree that we need a way of degrading gracefully when these components aren't on the hosted server(s).

The less impact we cause to the user, the better. If nothing else, I suppose we could simply give them a text box to enter their own connection string. Oh, and we could show a little scripting message saying something to the effect of "It appears your hosting environment does not have the following COM libraries installed: SQL-DMO, etc.... Please contact your System Administrator."
# re: Using SQL-DMO in your .NET app... mine's broken!
Gravatar Rofa avrail
Apr 13, 2007
this was my code in c# 2005 .net
but i get an error:

SQLDMO.Application fApp = new SQLDMO.ApplicationClass();
SQLDMO.NameList nl = (SQLDMO.NameList)fApp.ListAvailableSQLServers();
foreach (string strServer in nl)
{
MessageBox.Show(strServer);
}

this is the error I get:
Unable to cast COM object of type 'System.__ComObject' to interface

type 'SQLDMO.NameList'. This operation failed because the QueryInterface
call on the COM component for the interface with IID '{10022406-E260-11CF-
AE68-00AA004A34D5}' failed due to the following error: No such interface
supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
is there is any way to olve this thanks alot

# re: Using SQL-DMO in your .NET app... mine's broken!
Gravatar Steve Harman
Apr 14, 2007
Rofa, are you sure you have SQLDMO installed and configured on your dev box?
# re: Using SQL-DMO in your .NET app... mine's broken!
Gravatar Rofa avrail
Apr 25, 2007
i get it from the sql server 2000 cd from the sellect componants, tell me how to know if it is configured on my dev box?
# re: Using SQL-DMO in your .NET app... mine's broken!
Gravatar Steve Harman
Apr 25, 2007
Well, If you've installed the Client Tools, and followed the instructions above (namely, being sure to select "Development Tools" and "Headers and Libraries" from the Select Components screen.

So, make sure you're running the latest SQL Server Service Pack... as mentioned at the very bottom of this post.

If that doesn't help, I'm not sure what else I can tell you. Perhaps some Google searches using some of the key words from the error message you're seeing?
# re: Using SQL-DMO in your .NET app... mine's broken!
Gravatar Rofa avrail
Apr 27, 2007
thanks alot
# re: Using SQL-DMO in your .NET app... mine's broken!
Gravatar Swapnil Mohod
May 03, 2007
Hi,
I used this code also select the all the options from componants box but still there is
exception
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'SQLDMO.NameList'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{10022406-E260-11CF-AE68-00AA004A34D5}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at SQLDMO.ApplicationClass.ListAvailableSQLServers()
,if possible tell me the solution
# re: Using SQL-DMO in your .NET app... mine's broken! Getting the same error !!!
Gravatar Jitendra Kumar Gupta
Feb 22, 2008
I'm also getting the same error and totally unable to get out of this. I don't know what's going on under the hood. Is there some confirmed and reliable solution to this? Why this is happening. If some solution comes out, let me know.



Thanks.

G2
# re: Using SQL-DMO in your .NET app... mine's broken!
Gravatar Siddharth
Mar 14, 2008
Hi, I am getting an error while executing .sql file using DMO in .NET. I found the reason that the .sql file which is generated by Enterprise Manager is having "GO" statement inside .sql file.

Please provide me your suggestions.

Thanks,
Siddharth
Comments have been closed on this topic.