The SQL Distributed relational Object (SQL-DMO) library allows your VB6 application to automatically interoperate with SQL Servers. This is useful for getting information about SQL Servers, such as the state of the server or the available servers on the network.
To use the SQL-DMO library, you need to set up a reference to the Microsoft Sql-dmo Object Library.
The ListAvailableSQLServers method of the Application object returns a NameList object that contains a list of available servers on the network. The following code shows a way to populate a list box control by using this method:
Dim Objsqlapp as SQLDMO. Application
Dim Objnamelist as SQLDMO. NameList
Dim intcount as Integer
Set Objsqlapp = New SQLDMO. Application
Set objnamelist = Objsqlapp.listavailablesqlservers ()
For intcount = 1 to Objnamelist.count
Call List1.AddItem (Objnamelist.item (intcount))
Next
Another useful object in the SQL-DMO library is the SQL Server object. This object can be used to get information about a particular SQL Server. The Connect method establishes a connection to the database server and accepts three parameters: the database name, user name, and password. Once the object's connection succeeds, information about the server can be retrieved:
Dim Objsqlserver as SQLDMO. Sql server
Set objsqlserver = New SQLDMO. Sql server
Objsqlserver.loginsecure = True
Call Objsqlserver.connect ("MyServerName", "username", "password")
Debug.PrintobjSQLServer.Name
Debug.PrintobjSQLServer.HostName
Debug.PrintobjSQLServer.Status