Click to See Complete Forum and Search --> : sql servers
vin
August 14th, 2000, 04:50 AM
Hi,
I want to make a dialog that will connect my application to sql server and I want to load all available in an combobox so that the user can choose to which one he would like to connect.
Is there a way to get the name of all available(running) sql servers?
Thanks
Lothar Haensler
August 14th, 2000, 09:15 AM
there is a NetServerEnum API in Win32.
Specify the SV_TYPE_SQLSERVER flag to get all SQLServers in your network.
Lothar Haensler
August 14th, 2000, 09:20 AM
even easier:
add a reference to SQLDMO (for SQLServer) to your VB project and get the list via:
Dim d as new SQLDMO.Application
Dim nl as NameList
set nl = d.ListAvailableSQLServers
Dim i as Integer
for i = 1 to nl.Count
Debug.print nl.Item(i)
next i
vin
August 14th, 2000, 11:08 AM
Thanks!
Johnny101
August 14th, 2000, 06:27 PM
Two notes:
1) If you are using SQL Server 6.x then use the SQLOLE library, but if you are using 7 or 2000, then use the SQLDMO library.
2) You can also choose Add-Form from the Insert menu and then choose ODBC Login Form - there's code in there to list available DSN's (if yuo have ODBC connected servers).
just some thoughts,
John
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
Lothar Haensler
August 15th, 2000, 05:25 AM
Two notes:
1) SQLOLE doesn't offer the method mentioned, but only 2 others that do not totally match the one in SQLDMO.
2) an ODBC Login form doesn't help much.
- it lists DSNs that can refer to all types of data sources
- you don't need a DSN for connecting to an SQLServer, thus in many cases a DSN list will be incomplete.
just some thoughts ;-)
Johnny101
August 15th, 2000, 10:39 AM
Two more notes:
>1) SQLOLE doesn't offer the method mentioned, but only 2 others that do not totally match the one in SQLDMO.
True, but ListLocallyConfiguredSQLServers and ListAnnouncedNetworkSQLServers are all that's available if you're dealing with SQL 6.5 and I thought I would warn him that the object library names are different.
>2) an ODBC Login form doesn't help much.
>- it lists DSNs that can refer to all types of data sources
>- you don't need a DSN for connecting to an SQLServer, thus in many cases a DSN list will be incomplete.
Also true, but, in some environments all DB servers has a DSN entry, such as the place I am currently. My reply was obviously not an all around solution, nor was it meant to be, but I had hoped to offer at least a few more pieces of info. And, a little more info never hurt anyone. :)
Just a defensive rebuttal. ;-)
John
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.