Click here to Skip to main content
15,909,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have programmed with Sql server for some months but I usually pass "(local)" or "localhost" into the sqlconnection string. Now I need to connect to a specified server and I guess I have to pass a Sql Server name into the connection string. But I didn't care what the names were when I installed Sqlserver. Could you please let me know how to view those names again? I also want to list all the server names on my computer and I have googled for hours but the results still confuse me. Some ones suggest using Registry but I can only find INSTANCES of sql server not server names, some ones suggest using SQLSMO but can it list all server names for me?(or only instances) (I haven't tried this yet), some ones suggest using SqlDataSourceEnumerator class but I have tested it without any expected result, Microsoft says it can work sometimes not always and I think it is helpless to me.
Could you please dissect the methods above or give me any other solutions?
Your helps would be highly appreciated!
Thank you very much!
Posted
Comments
nagendrathecoder 4-Nov-11 8:14am    
AFAIK we pass instance name of sqlserver to connection string.
Is it not working like that?
[no name] 4-Nov-11 10:33am    
I don't think instance name can work, my splserver has default name called "MSSQLSERVER" and I tried passing into the connection string instead of "localhost" and the RDBMS couldn't realize what it is.
Could you tell me if you have any idea?
Thank you very much!
[no name] 4-Nov-11 10:36am    
Oops, I mean the default name of my sql server instance. In fact, I'm not sure if they (server name and instance name) are the same.
Thank you!

Have a look at this link.

Find SQL Server Instances - C#
 
Share this answer
 
v2
Comments
[no name] 4-Nov-11 10:57am    
Oh no, I tested that SqlDataSourceEnumerator and I have mentioned in my question that it is helpless to me. The proof is that it couldn't list any server instances on my local machine.
Thank you very much!
here is code project article. Locate SQL Server instances on the local network[^]
 
Share this answer
 
Comments
[no name] 4-Nov-11 11:14am    
The article involves some very new classes to me although it may be very nice to solve my problem.
Isn't any other simpler one?
Thank you very much!

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