Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL-DMO doesn't return Server available
Message
From
20/01/2009 13:46:05
Peter Wagner
Point Informática Ltda.
Limeira, Brazil
 
 
To
20/01/2009 11:16:40
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2000
Application:
Desktop
Miscellaneous
Thread ID:
01375255
Message ID:
01375574
Views:
37
>>Hi, I attempt to discover if a SQL Server is available in the network, so I run the code below, but it returns that there is no SQL Server there, but I have a SQl Server in the PC and I can connect to it.
>>What im missing here?
>>Thanks in Advance
>>
>>Peter
>>
>>
>>LOCAL oSQLDMO AS SQLDMO.SQLserver
>>LOCAL oNames AS SQLDMO.NameList
>>oSQLDMO = CREATEOBJECT("SQLDMO.SQLserver")
>>oNames = oSQLDMO.APPLICATION.ListAvailableSQLServers()
>>FOR ix=1 TO oNames.COUNT
>> ? oNames.ITEM[ix]
>>ENDFOR
>>
>
>Peter,
>It wouldn't work. Neither would some APIs (one is used by VFP data explorer). Those all assume SQL2000 and fail with 2005/2008 servers unless you explicitly change driver name.
>
>These work for installed instances and registered servers. I haven't seen a reliable way to discover what is available on a network:
>
>
Local oSQLDMO2 as SQLDMO.SQLserver2,;
>  oSQLDMO As SQLDMO.SQLserver,;
>  oSG As SQLDMO.ServerGroup,;
>  oSrv As SQLDMO.RegisteredServer
>
>** get installed instances
>oSQLDMO2 = Createobject("SQLDMO.SQLserver2")
>oNames2 = oSQLDMO2.ListInstalledInstances()
>For ix=1 To oNames2.Count
>  ? oNames2.Item[ix]
>Endfor
>? '***************'
>
>*** Get registered servers
>oSQLDMO = Createobject("SQLDMO.SQLserver")
>? 'SQL server groups count:', oSQLDMO.Application.ServerGroups.Count
>For Each oSG In oSQLDMO.Application.ServerGroups
>  ? Textmerge('SQL server group name:[<<oSG.Name>>] have <<oSG.RegisteredServers.Count>> registered servers')
>  For Each oSrv In oSG.RegisteredServers
>    ? oSrv.Name
>  Endfor
>Endfor
>
>PS: MS documented that SQLDMO (and probably the APIs it uses) would be dropped in future SQL server versions. SQL SMO is the way to go but I don't know if there is a way to use it from VFP.

Hi Cetin,
this is something what I'm looking for.
Just a question, will it show a linked server?

I have to test if a specific SQL Server is connected, if it's not connected, connect using "EXEC sp_addlinkedserver....." .

I made a test but the result is mixed, in some PC it only returns the local SQL Server (developer), in other it doesnt returns the SQL Server from the network, even if the server is mapped in the PC station.
Here it doesnt showed the linked server in no PC station, any ideia why?
I thing this is a stranger behavior why in some PC's it works an in others not..

I made a test with SQL 2000 and it failed.
I the past the first code above always worked in SQL 2000, now it doesnt returns any walued even it theres a SQL Server in the PC station....
LOCAL oSQLDMO AS SQLDMO.SQLserver
LOCAL oNames AS SQLDMO.NameList
oSQLDMO = CREATEOBJECT("SQLDMO.SQLserver")
oNames = oSQLDMO.APPLICATION.ListAvailableSQLServers()
FOR ix=1 TO oNames.COUNT
 ? oNames.ITEM[ix]
ENDFOR
The same mixed results in SQL 2005 and 2008

Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform