How to use the ListAvailableSqlServers in c#

06/11/2004 - 04:24 por Anonimo | Informe spam
Here is my code:

///////////////////////////////////////////////////////////////////////////
SQLDMO._Application SqlServer = new ApplicationClass();
try
{

SQLDMO.NameList servers = SqlServer.ListAvailableSQLServers();

for(int i=0;i<servers.Count;i++)
MessageBox.Show(servers.Item(i));

}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}



///////////////////////////////////////////////////////////////////////////
The compiler tell me : Queryinterface is failed of the SQLDMO.NameList

What shall I do ?

Preguntas similare

Leer las respuestas

#1 José Miguel Torres
08/11/2004 - 12:50 | Informe spam
Hi, try

for(int i=0;i<servers.Count;i++)
MessageBox.Show(servers.Item(i).ToString());



and look this link http://www.csharphelp.com/archives2...ve342.html

regards


José Miguel Torres
jtorres_diaz~~ARROBA~~terra.es
http://jmtorres.blogspot.com
escribió en el mensaje
news:#zpIf$
Here is my code:




///////////////////////////////////////////////////////////////////////////
SQLDMO._Application SqlServer = new ApplicationClass();
try
{

SQLDMO.NameList servers = SqlServer.ListAvailableSQLServers();

for(int i=0;i<servers.Count;i++)
MessageBox.Show(servers.Item(i));

}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}






///////////////////////////////////////////////////////////////////////////
The compiler tell me : Queryinterface is failed of the SQLDMO.NameList

What shall I do ?





Respuesta Responder a este mensaje
#2 Anonimo
09/11/2004 - 09:38 | Informe spam
Now the question is ListAvailableSqlServers make for the error!
Even if I tried your code
{
SQLDMO.Application App= new ApplicationClass();
SQLDMO.NameList servers = App.ListAvailableSQLServers();
}
The same error appeared!!!

God help me!


"Jos?Miguel Torres" <jtorres_diaz~~ARROBA~~terra.es> дÈëÏûÏ¢ÐÂÎÅ
:#
Hi, try

> for(int i=0;i<servers.Count;i++)
> MessageBox.Show(servers.Item(i).ToString());

and look this link http://www.csharphelp.com/archives2...ve342.html

regards


Jos?Miguel Torres
jtorres_diaz~~ARROBA~~terra.es
http://jmtorres.blogspot.com
escribi?en el mensaje
news:#zpIf$
> Here is my code:
>
>



///////////////////////////////////////////////////////////////////////////
> SQLDMO._Application SqlServer = new ApplicationClass();
> try
> {
>
> SQLDMO.NameList servers = SqlServer.ListAvailableSQLServers();
>
> for(int i=0;i<servers.Count;i++)
> MessageBox.Show(servers.Item(i));
>
> }
> catch(Exception e)
> {
> MessageBox.Show(e.ToString());
> }
>
>
>
>



///////////////////////////////////////////////////////////////////////////
> The compiler tell me : Queryinterface is failed of the SQLDMO.NameList
>
> What shall I do ?
>
>
>
>
>


Respuesta Responder a este mensaje
#3 José Miguel Torres
09/11/2004 - 10:03 | Informe spam
Well, Are you using VS .NET 2002 or 2003? And SQL Server 2000 with any SP? I
know a bug in VS .NET 2002 COM interops if you don't have SP3 in your SQL
Server...


escribió en el mensaje
news:u#
Now the question is ListAvailableSqlServers make for the error!
Even if I tried your code
{
SQLDMO.Application App= new ApplicationClass();
SQLDMO.NameList servers = App.ListAvailableSQLServers();
}
The same error appeared!!!

God help me!


"Jos?Miguel Torres" <jtorres_diaz~~ARROBA~~terra.es> дÈëÏûÏ¢ÐÂÎÅ
:#
> Hi, try
>
> > for(int i=0;i<servers.Count;i++)
> > MessageBox.Show(servers.Item(i).ToString());
>
> and look this link http://www.csharphelp.com/archives2...ve342.html
>
> regards
>
>
> Jos?Miguel Torres
> jtorres_diaz~~ARROBA~~terra.es
> http://jmtorres.blogspot.com
> escribi?en el mensaje
> news:#zpIf$
> > Here is my code:
> >
> >
>



///////////////////////////////////////////////////////////////////////////
> > SQLDMO._Application SqlServer = new ApplicationClass();
> > try
> > {
> >
> > SQLDMO.NameList servers = SqlServer.ListAvailableSQLServers();
> >
> > for(int i=0;i<servers.Count;i++)
> > MessageBox.Show(servers.Item(i));
> >
> > }
> > catch(Exception e)
> > {
> > MessageBox.Show(e.ToString());
> > }
> >
> >
> >
> >
>



///////////////////////////////////////////////////////////////////////////
> > The compiler tell me : Queryinterface is failed of the SQLDMO.NameList
> >
> > What shall I do ?
> >
> >
> >
> >
> >
>
>


Respuesta Responder a este mensaje
#4 Anonimo
09/11/2004 - 11:00 | Informe spam
I use Vs.net 2003 and My SqlServer have sp3


"Jos?Miguel Torres" <jtorres_diaz~~ARROBA~~terra.es> дÈëÏûÏ¢ÐÂÎÅ
:#
Well, Are you using VS .NET 2002 or 2003? And SQL Server 2000 with any SP?


I
know a bug in VS .NET 2002 COM interops if you don't have SP3 in your SQL
Server...


escribi?en el mensaje
news:u#
> Now the question is ListAvailableSqlServers make for the error!
> Even if I tried your code
> {
> SQLDMO.Application App= new ApplicationClass();
> SQLDMO.NameList servers = App.ListAvailableSQLServers();
> }
> The same error appeared!!!
>
> God help me!
>
>
> "Jos?Miguel Torres" <jtorres_diaz~~ARROBA~~terra.es> дÈëÏûÏ¢ÐÂÎÅ
> :#
> > Hi, try
> >
> > > for(int i=0;i<servers.Count;i++)
> > > MessageBox.Show(servers.Item(i).ToString());
> >
> > and look this link http://www.csharphelp.com/archives2...ve342.html
> >
> > regards
> >
> >
> > Jos?Miguel Torres
> > jtorres_diaz~~ARROBA~~terra.es
> > http://jmtorres.blogspot.com
> > escribi?en el mensaje
> > news:#zpIf$
> > > Here is my code:
> > >
> > >
> >
>



///////////////////////////////////////////////////////////////////////////
> > > SQLDMO._Application SqlServer = new ApplicationClass();
> > > try
> > > {
> > >
> > > SQLDMO.NameList servers = SqlServer.ListAvailableSQLServers();
> > >
> > > for(int i=0;i<servers.Count;i++)
> > > MessageBox.Show(servers.Item(i));
> > >
> > > }
> > > catch(Exception e)
> > > {
> > > MessageBox.Show(e.ToString());
> > > }
> > >
> > >
> > >
> > >
> >
>



///////////////////////////////////////////////////////////////////////////
> > > The compiler tell me : Queryinterface is failed of the


SQLDMO.NameList
> > >
> > > What shall I do ?
> > >
> > >
> > >
> > >
> > >
> >
> >
>
>


Respuesta Responder a este mensaje
#5 Pedro Luna Montalvo, MVP
10/11/2004 - 03:31 | Informe spam
Try with this code:

using System;
using System.Reflection;

internal class RetrieveSqlServerListApp {

public static void Main() {
// Invoke the ListAvailableSQLServers() method for a
SQLDMO.Application instance
Type oSqlDmoAppType = Type.GetTypeFromProgID("SQLDMO.Application");
object oSqlDmoApp = Activator.CreateInstance(oSqlDmoAppType);

object oSqlDmoListNames oSqlDmoAppType.InvokeMember("ListAvailableSQLServers",
BindingFlags.InvokeMethod,
null, oSqlDmoApp, new object[] {});

// Retrieve the number of available servers
Type oSqlDmoListNamesType = oSqlDmoListNames.GetType();

int nNumElementos = (int)
oSqlDmoListNamesType.InvokeMember("Count",
BindingFlags.GetProperty,
null, oSqlDmoListNames, new object[] {});

// Retrieve each SQL Server name
for (int i = 1; i <= nNumElementos; i++) {
object oSqlServer = oSqlDmoListNamesType.InvokeMember("Item",
BindingFlags.InvokeMethod,
null, oSqlDmoListNames, new object[] {i});

Console.WriteLine(oSqlServer.ToString());
}
}

}



Saludos
Pedro Luna, [MVP VB.NET]
Gye, Ecu
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida