This script will only find those servers (and instances) that are broadcasting their existence, and requires execute permissions on XP_CMDShell.
CREATE PROCEDURE dbo.ListLocalServers AS BEGIN SET NOCOUNT ON CREATE TABLE #servers(sname VARCHAR(255)) INSERT #servers EXEC master..XP_CMDShell 'OSQL -L' -- play with ISQL -L too, results differ slightly DELETE #servers WHERE sname='Servers:' SELECT LTRIM(sname) FROM #servers WHERE sname != 'NULL' DROP TABLE #servers END |
So from ASP, you could do this:
<% set conn = CreateObject("ADODB.Connection") conn.open "<connection string>" set rs = conn.execute("EXEC ListLocalServers") do while not rs.eof response.write rs(0) & "<br>" rs.movenext loop rs.close set rs = nothing %> |
(Note that this won't tell you which port SQL Server is listening on.)
Another option is to use SQL-DMO's .ListAvailableSQLServers() method. Rather than pretend to be a SQL-DMO expert, I'll simply point you to
this post.
Gert has some great information as well:
Enumerate SQL Servers using OLE-DB Enumerate SQL Servers using ODBC Enumerate SQL Servers using LAN manager