How can i scan for SQL server in my application
Hi, Tim.
One way to do this makes use of SQL-DMO COM objects. To use SQL-DMO, you
must have the SQL-DMO files on the PC running the app. If you've installed
MSDE with your Visual Studio install, you should have this already. Look
for a file called sqldmo.dll. The MS Knowledge Base article Q258157
describes how to deploy SQL-DMO to support an application.
Once SQL-DMO is in place, you have to create a COM Interop wrapper for
SQL-DMO. This is much easier than it sounds, because the IDE basically does
everything for you. In the Solution Explorer, select the project you want
to be able to access the SQL Server list in. Select References, and
right-click to get the shortcut menu. Choose Add Reference, and you'll get
the Add Reference dialog box. Choose the COM tab, and look for Microsoft
SQLDMO Object Library, version 8.0 (make sure you use 8.0, not 7, because it
won't work, as I discovered the hard way...). Make sure this name appears in
Selected Components, then click OK. .NET will create a reference for you,
which should be called SQLDMO, and is actually a file called
Interop.SQLDMO.dll.
Once you have the reference, you can work with the SQL-DMO objects. I
needed to do something like what you are doing, plus have access to logins,
users, roles etc. on a SQL Server and in a specific database.
Here's a snippet from the form I used to display available servers:
Dim oSQL As New SQLDMO.Application()
Dim oServerNames As SQLDMO.NameList
'use SQL-DMO to list server names
oServerNames = oSQL.ListAvailableSQLServers
For i = 1 To oServerNames.Count
Me.cboServer.Items.Add(oServerNames.Item(i)) ' the server
list shows up in a combo box
Next
oServerNames = Nothing
oSQL = Nothing
You can get more information about using SQL-DMO in your SQL Server
documentation.
Hope this helps,
Jim.
Quote:
> Hi
> I am making a windows application and for that application I am making a
> login screen, where a user have to choice a server type.
> For an Access server it is no problem to show a OpenFileDialog but I want
> to show something similar for the SQL server.
> I have seen in the .NET IDE there is a function where you make a new
> connection to a database, then you can choice a server from a list of
> servers, but how do I make that list of servers ?
> Thanks
> Tim P