finding sql servers on the network.
Hello,
I am creating a application that can connect any sql server on the network.
The customer would like a dialog box to be able to find a instance of a server, and then enter the password and username to get a list of all the database they want to connect to.
Does anyone have any examples projects in vb.net that does something like this.
I will be most grateful for any code.
Thanks in advance,
Steve
Re: finding sql servers on the network.
Actually finding general SQL servers on the network could prove troublesome. The idea you begin with when considering an SQL server is that you know exactly where it is at.
You'd probably have to adopt a portscanner-type technique. However, this would be limited to the specific local IP range that you set (example: your app sees that an adapter has a local IP of 192.168.0.5, so it checks IPs 192.168.0.1-254). The main problem you are still faced with in this situation is that the SQL server must be running on a pre-defined port, or a small set of pre-defined ports.
A full network scan may work, but it will be important that any internal security mechanisms do not stop it, and the servers must all be in one general IP range to be found, hopefully avoiding weird gateway hops into other ranges.
I hope this helps out a bit. I primarily deal with SQL in Java, but I would be interested in taking this project up if you'd like. You can see http://www.vbforums.com/showthread.php?t=429437 in that case. (admins: I know I'm blatantly advertising here, so please let me know if this sort of thing is unacceptable :) )
Re: finding sql servers on the network.
You may want to have a look at http://pinvoke.net/default.aspx/netapi32.netserverenum
You can call NetServerEnum and pass SV_TYPE_SQLSERVER as a flag.
The code is in C# but shouldn't be too hard in VB.NET.
If you're on the .net framework v 2.0 be sure and use a List<T> instead of the ArrayList used in the sample code for a performance boost.
Re: finding sql servers on the network.