Click here to Skip to main content
15,909,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to list the installed Sql Servers and instances in Local Machine using VB.Net?
Posted

1 solution

Try starting here:
VB
Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
Dim dt As DataTable = instance.GetDataSources()
For Each row As System.Data.DataRow In dt.Rows
    Console.WriteLine("ServerName = {0}", row("ServerName"))
Next
 
Share this answer
 
Comments
kgmmurugesh 2-Mar-15 8:00am    
It shows network servers only. I want local server (My Computer)
OriginalGriff 2-Mar-15 8:14am    
Why?
The only time you should be using a local server is in development: proliferating SQL servers in a production environment is a very, very bad idea.

And for development, it's simple: you just need to use VS and it'll give you the complete connection string...
kgmmurugesh 2-Mar-15 8:23am    
No, What I want is to check the given sql server instance is in Local Computer or Network Computer?
OriginalGriff 2-Mar-15 8:34am    
Two things you can do:
1) Look at the instances returned, and check for you PC host name at the start.
2) Connect to teh server, and issue the query:
SELECT HOST_NAME()
which will return the PC ID. But...what it will return for a clustered SQL farm, I don't know... :laugh:
kgmmurugesh 2-Mar-15 8:38am    
It will not return instances installed in my PC. It only return the instances installed in network systems.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900