Tuesday, March 27, 2012

Enumerate SQL server list?

Anyone know how to enumerate the SQL Servers on a network using .Net? I can
do this with VB6, but howso in .Net?Hi Earl,
One way would be:
Q287737
http://support.microsoft.com/defaul...;EN-US;Q287737&
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com
"Earl comcast net>" <brikshoe<at.> wrote in message
news:%23YXdcy5FEHA.2208@.TK2MSFTNGP09.phx.gbl...
> Anyone know how to enumerate the SQL Servers on a network using .Net? I
can
> do this with VB6, but howso in .Net?
>|||I haven't seen how to do it using the .Net Framework, but if the method you
use for VB6 provides a COM object interface, you can include a reference to
the library in your project. .Net will create the classes required for the m
ashalling between the manag
ed and unmanaged code.|||Earl,
This is worth looking at to give you some ideas. It's not .net though.
http://sqldev.net/misc/ListSQLSvr.htm
Mark Allison, SQL Server MVP
http://www.markallison.co.uk|||Hi Mika,
This is essentially the same thing I'm doing now in VB6, but I was looking
to see if there was another way to not use a COM reference in order to do
this with .Net. Maybe this is the wrong way of looking at this -- what am I
giving up using COM here? Incidentally, I've been on that RightHand site in
the past, good stuff you folks are building over there.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:OyYPu47FEHA.3188@.TK2MSFTNGP10.phx.gbl...
> Hi Earl,
> One way would be:
> Q287737
> http://support.microsoft.com/defaul...;EN-US;Q287737&
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & software developmen
t
> miha at rthand com
> www.rthand.com
> "Earl comcast net>" <brikshoe<at.> wrote in message
> news:%23YXdcy5FEHA.2208@.TK2MSFTNGP09.phx.gbl...
> can
>|||Miha,
Using this VB6 method, I get an invalid cast exception when I try to create
an object for the namelist (Dim oNames As SQLDMO.NameList). Even with a
Try-Catch, I still get the exception: "Query Interface for interface
SQLDMO.Namelist failed." Is this a COM wrapper issue?
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:OyYPu47FEHA.3188@.TK2MSFTNGP10.phx.gbl...
> Hi Earl,
> One way would be:
> Q287737
> http://support.microsoft.com/defaul...;EN-US;Q287737&
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & software developmen
t
> miha at rthand com
> www.rthand.com
> "Earl comcast net>" <brikshoe<at.> wrote in message
> news:%23YXdcy5FEHA.2208@.TK2MSFTNGP09.phx.gbl...
> can
>|||Hehe, thanks Mark... I've read this and every article I could find on the
web about this topic and they all pertain to VB6. Gets me close though.
"Mark Allison" <marka@.no.tinned.meat.mvps.org> wrote in message
news:814797B0-7FBF-4D8A-8ABA-0CB3B8EBCE08@.microsoft.com...
> Earl,
> This is worth looking at to give you some ideas. It's not .net though.
> http://sqldev.net/misc/ListSQLSvr.htm
> --
> Mark Allison, SQL Server MVP
> http://www.markallison.co.uk|||Thanks Al, the problem I'm having is that apparently one of the classes is
not being created because I get an error trying to assign the list object to
the name object.
Dim oSQLNames As SQLDMO.NameList
Dim oSQLApp As SQLDMO.Application
oSQLApp = New SQLDMO.Application
'getting invalid cast error on this assignment
oSQLNames = oSQLApp.ListAvailableSQLServers
"Al" <al_davie@.hotmail.com> wrote in message
news:A7B8DA42-0D39-4529-B2AE-9C8DAED59F1B@.microsoft.com...
> I haven't seen how to do it using the .Net Framework, but if the method
you use for VB6 provides a COM object interface, you can include a reference
to the library in your project. .Net will create the classes required for
the mashalling between the managed and unmanaged code.|||Hi,
I've just tried your code fragment, and I don't get a problem.
Are you getting the problem in the debugger or deployed ?
Here are the facts for my set-up :-
VS 2003 / Framework 1.1
SQL Server 2000 SP3 (not Sp3a)
Windows 2000Pro SP4
Running via debugger, so not deployed.
Visual Basic Windows application
Option Explicit ON
Option Strict OFF
Option Compare Binary
The Imports and References are all the defaults for a Windows Application, e
xcepted added the SQLDMO Object lib version 8.0
Let me know how you get on|||If you're getting stuck, send me the source.
Email my Hotmail account, i'll send you my main email address.

No comments:

Post a Comment