DF_DATABASE_ID

The handle of the database connection.

Level

Database

Supported by

The DataFlex SQL Drivers (SQL Server, DB2 and ODBC), revision 5 and higher

Type

Handle, temporary

Access

Read Only

Values

Any valid handle value

Syntax

Use cli.pkg

 

Get_Attribute DF_DATABASE_ID of {driverNumber} {serverNumber} to {HandleVariable}

Driver Configuration Keyword

None

Remarks

The database API stores information about database drivers and the connections these drivers have in a layered way. You can enumerate through the loaded drivers and every connection opened by these drivers by using the DF_NUMBER_DRIVERS, DF_DRIVER_NAME, DF_DRIVER_NUMBER_SERVERS, and DF_DRIVER_SERVER_NAME global attributes.

The DF_DATABASE_ID attribute returns the handle of the database connection. This handle serves as the database identification when obtaining other database attributes.

The sample code below shows all database handles of all connections to SQL Server.

Function DriverIndex String sDriver Returns Integer
 String sCurrentDriver
 Integer iDriver iNumDrivers

 Get_Attribute DF_NUMBER_DRIVERS To iNumDrivers
 For iDriver From 1 To iNumDrivers
   Get_Attribute DF_DRIVER_NAME of iDriver to sCurrentDriver
   If (Uppercase(sDriver) = Uppercase(sCurrentDriver)) ;
       Function_Return iDriver
 Loop
 Function_Return 0
End_Function

 

Procedure ShowServerList
  Integer iDriver iNumServers iServer
  String sServer
  Handle hDatabase
 

    Get DriverIndex "MSSQLDRV" To iDriver
  If (iDriver <> 0) Begin
      Showln "Databases:"
      Get_Attribute DF_DRIVER_NUMBER_SERVERS of iDriver to iNumServers
      For iServer from 1 to iNumServers
          Get_Attribute DF_DRIVER_SERVER_NAME Of iDriver iServer To sServer
          Show " - " sServer
          Get_Attribute DF_DATABASE_ID of iDriver iServer to hDatabase
          Showln ", Database handle: " hDatabase
      Loop
  End
End_Procedure