Class: cMSSQLHandler

Properties  Events  Methods    Index of Classes

Implements functionality specific to SQL Server.

Hierarchy

cObject
---Array
------cCLIHandler
---------cMSSQLHandler

Library: Common (Windows and Web Application) Class Library

Package: MSSqldrv.pkg

Description

Enumerating Servers and Databases

The enumeration functions available will store the lists they enumerate in the object itself. After calling an enumeration function one can get the enumerated values by using the value function.

Function EnumerateServers Returns Integer
Function EnumerateDatabases String sServer String sUser String sPassWord Returns Integer

If, for example, we would like to show all servers and available databases therein we would use:

Use MSSQLDRV.pkg

Procedure ShowAllServersAndDatabases
    Handle hoSQLHandler
    Integer iNumServers
    Integer iNumDatabases
    Integer iServerCount
    Integer iDatabaseCount

    Get Create U_cMSSQLHandler To hoSQLHandler
    If (hoSQLHandler > 0) Begin
        Get EnumerateServers Of hoSQLHandler To iNumServers
        For iServerCount From 0 To (iNumServers - 1) 
            Showln "SERVER: " (Value(hoSQLhandler, iServerCount))
            //*** Assuming every server has an sa account with
            //*** empty password
            Get EnumerateDatabases of hoSQLHandler ;
            (Value(hoSQLhandler)) "sa" "" To iNumDatabases
            For iDatabaseCount From 0 To (iNumDatabases - 1)
                Showln " " (Value(hoSQLHandler, iDatabaseCount))
            Loop
            //*** Need to enumerate servers again, the enumerate
            //*** databases overwrites the server information
            Get EnumerateServers Of hoSQLHandler To iNumServers
        Loop
        Send Destroy Of hoSQLHandler
    End
End_Procedure // ShowAllServersAndDatabases

The EnumerateDatabases function expects a user account and password. It is not possible to use NT Authentication to enumerate databases.