Attribute VB_Name = "dbInfo"
'---------------------------------------------------------------------------
'
' (c) Copyright IBM Corp. 2007 All rights reserved.
' 
' The following sample of source code ("Sample") is owned by International 
' Business Machines Corporation or one of its subsidiaries ("IBM") and is 
' copyrighted and licensed, not sold. You may use, copy, modify, and 
' distribute the Sample in any form without payment to IBM, for the purpose of 
' assisting you in the development of your applications.
' 
' The Sample code is provided to you on an "AS IS" basis, without warranty of 
' any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR 
' IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
' MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Some jurisdictions do 
' not allow for the exclusion or limitation of implied warranties, so the above 
' limitations or exclusions may not apply to you. IBM shall not be liable for 
' any damages you suffer as a result of using, copying, modifying or 
' distributing the Sample, even if IBM has been advised of the possibility of 
' such damages.
'---------------------------------------------------------------------------
'
' SOURCE FILE NAME: dbInfo.bas
'
' SAMPLE: Get info at database level
'
' FORMS USED:
'         frmMain (Demo.frm)
'
'----------------------------------------------------------------------------
'
' For more information on the sample programs, see the README file.
'
' For information on building ADO applications with Visual Basic, 
' see the Developing ADO.NET and OLE DB Applications book.
'
' For information on using SQL statements, see the SQL Reference.
'
' For the latest information on programming, compiling, and running DB2
' applications, visit the DB2 Information Center:
'     http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp
'---------------------------------------------------------------------------

Option Explicit

'This procedure returns the connection information.
Public Function ConnectInfo(cn As ADODB.Connection) As String
  
  'define an error handler so that partial information
  'can still be obtained in case of error.
  On Error GoTo ConnectInfo_Exit

  'set up the connection information string
  Dim strConnectInfo As String
  strConnectInfo = _
    "Connection String: " & vbTab & cn.ConnectionString & vbCr
  strConnectInfo = strConnectInfo & _
    "ADO Version: " & cn.Version & vbCr
  strConnectInfo = strConnectInfo & _
    "Command Timeout: " & cn.CommandTimeout & vbCr
  strConnectInfo = strConnectInfo & _
    "Connection Timeout: " & cn.ConnectionTimeout & vbCr
  strConnectInfo = strConnectInfo & _
    "State: " & GetState(cn.State) & vbCr
  strConnectInfo = strConnectInfo & _
    "Cursor Location: " & GetCursor(cn.CursorLocation) & vbCr
  strConnectInfo = strConnectInfo & _
    "Isolation Level: " & GetIsolation(cn.IsolationLevel) & vbCr
  strConnectInfo = strConnectInfo & _
    "Attributes: " & GetAttribute(cn.Attributes) & vbCr
  strConnectInfo = strConnectInfo & _
    "Mode: " & GetMode(cn.Mode) & vbCr

ConnectInfo_Exit:
  ConnectInfo = strConnectInfo

End Function

'This procedure gets description for the attribute property.
Private Function GetAttribute(intAttribute As Long) As String
  
  Select Case intAttribute
    Case adXactAbortRetaining
      GetAttribute = "adXactAbortRetaining"
    Case adXactCommitRetaining
      GetAttribute = "adXactCommitRetaining"
    Case (adXactAbortRetaining + adXactCommitRetaining)
      GetAttribute = "adXactAbortRetaining, adXactCommitRetaining"
    Case Else
      GetAttribute = "Unknown"
  End Select

End Function

'This procedure gets description for the cursor location.
Private Function GetCursor(intCursor As Integer) As String
  
  Select Case intCursor
    Case adUseClient
      GetCursor = "adUseClient"
    Case adUseNone
      GetCursor = "adUseNone"
    Case adUseServer
      GetCursor = "adUseServer"
    Case Else
      GetCursor = "Unknown"
  End Select

End Function

'This procedure gets description for the isolation level.
Private Function GetIsolation(intIsolation As Integer) As String
  
  Select Case intIsolation
    Case adXactUnspecified
      GetIsolation = "adXactUnspecified"
    Case adXactChaos
      GetIsolation = "adXactChaos"
    Case adXactReadUncommitted
      GetIsolation = "adXactReadUncommitted"
    Case adXactCursorStability
      GetIsolation = "adXactCursorStability"
    Case adXactRepeatableRead
      GetIsolation = "adXactRepeatableRead"
    Case adXactIsolated
      GetIsolation = "adXactIsolated"
    Case Else
      GetIsolation = "Unknown"
  End Select

End Function

'This procedure gets description for the mode property.
Private Function GetMode(intMode As Integer) As String
  
  Select Case intMode
    Case adModeRead
      GetMode = "adModeRead"
    Case adModeReadWrite
      GetMode = "adModeReadWrite"
    Case adModeRecursive
      GetMode = "adModeRecursive"
    Case adModeShareDenyNone
      GetMode = "adModeShareDenyNone"
    Case adModeShareDenyRead
      GetMode = "adModeShareDenyRead"
    Case adModeShareDenyWrite
      GetMode = "adModeShareDenyWrite"
    Case adModeShareExclusive
      GetMode = "adModeShareExclusive"
    Case adModeWrite
      GetMode = "adModeWrite"
    Case Else
      GetMode = "adModeUnknown"
  End Select

End Function

'This procedure gets description for the state property.
Public Function GetState(intState As Integer) As String
  
  Select Case intState
    Case adStateClosed
      GetState = "adStateClosed"
    Case adStateOpen
      GetState = "adStateOpen"
    Case Else
      GetState = "Unknown"
  End Select

End Function