How can I test ODBC connection strings outside of CPM?

How can I test ODBC connection strings outside of CPM?

216
Created On 11/10/26 10:55 AM - Last Modified 11/10/26 12:59 PM


Objective



Many of the database-type CPM plugins utilize an ODBC (Open Database Connectivity) driver, installed on the CPM server, to connect to remote databases.  One of the available methods for this connection is an ODBC connection string.  An ODBC connection string is comprised of a sequence of keywords and their corresponding values.  The format of the string, including the specific keywords used, depends on the type of database installed on the target.

 

Note: Configuring a valid connection string is a prerequisite (the same as configuring valid permissions and ensuring the correct network ports are open) that must be completed before the plugin can be tested.  For direct assistance in doing so, please involve your DBA and/or database vendor Support.  Supplemental resources include the respective Idira CPM plugin documentation, as well as the following knowledge article: Example ODBC Connection Strings


This article walks you through the steps to test an ODBC connection string via PowerShell on the CPM.  The script has been written such that it directly emulates the same methods that the CPM plugin uses to create a valid ODBC connection to the target database.  The output of the script may be useful when troubleshooting with the respective teams noted above.  Before attempting to use the CPM plugin itself, we strongly recommend utilizing this testing method first.

 

Important: This test simulates a CPM Verify action.  It cannot simulate Change and/or Reconcile actions.

 

Note regarding testing with Microsoft SQL Server: If utilizing this script to test whether or not a Windows-based reconcile account, used for reconciling a SQL Server target account, can connect via ODBC, please see the addendum at the bottom of this article.

 



Environment


12.2;12.6;14.2;14.5;14.6 Privileged Access Manager (PAM, self-hosted);Privilege Cloud Central Policy Manager (CPM)

Procedure


 
1. Download the 'Test-ODBCConnectionString.txt' text file that is attached to this article.  The file contains the PowerShell script needed for this test.
 
Note: The script is updated semi-regularly.  Updates are made for compatibility reasons, customer-usability enhancements, and more.  For the most accurate results, please ensure that you are using the most up-to-date version of the script.
 

2. On the CPM server, Launch "Windows PowerShell ISE (x86)" as Administrator.
 
Note: This test MUST be run with the 32-bit version of PowerShell ISE in order to use the same 32-bit driver that CPM will use.  Additionally, the script MUST be run as Administrator, as there is no way to confirm whether or not a local user has the correct permissions to the ODBC driver.  The script will automatically terminate if run using 64-bit PowerShell, OR if run using a non-local admin account.
 

3. In the PowerShell Script Pane (the white section), copy and paste the entire contents from the text file.
 
Note: If you do not see the Script Pane upon opening PowerShell ISE, it can be added by selecting the View tab on the Menu bar, followed by selecting Show Script Pane (or press Ctrl+R).
 
 
4. Configure a valid connection string:
 
A) The script is configured to allow for cleartext or encrypted passwords to be used.  By default, NEITHER option is enabled; you MUST choose which one to use:
 
    • To use an encrypted password, add a pound sign (#) to the beginning of line 12 in the code (do NOT remove the trailing <#).
    • To use a cleartext password, add a pound sign (#) to the beginning of line 19 in the code (do NOT remove the trailing <#).
 
B) Next, configure the connection string such that the format and syntax are valid for the specific database type running on the target.  For more information on how to create a properly formatted, syntactically valid, connection string, refer to the documentation from the respective database vendor.  You may also refer to the respective CPM plugin documentation for assistance.
 
Separately, the following knowledge article has been created to aid in configuring the connection string: Example ODBC Connection Strings
 
Note: The connection string examples from the official database vendor documentation supersede any and all connection string examples shown in the respective CPM plugin documentation, as well as the KB article linked above.
 
C) Once you've configured a valid connection string, update the corresponding line in the script:
 
    • If using an encrypted password, update the $connectionstring variable on line 16.
    • If using a cleartext password, update the $connectionstring variable on line 20.
 
Note: When updating either line listed above, ensure that changes are only made inside the double quotes.  Ensure that the preceding $connectionstring = ", as well as trailing ", are not altered.
 
D) Finally, once the connection string format is correct, fill in each of the values.  For instance, replace %target_address% with the address of the target database server (ensure you remove the surrounding percentage sign (%) characters as well).
 
 
5. Once your connection string is correctly configured, in PowerShell, press the green Play button on the ToolBar (or press F5), to execute the script.  If you chose to use the encrypted password option, you'll receive a prompt to manually type in the password.

 
6. The output of the script will be displayed in the PowerShell Console pane (the blue section) as well output to a log file, C:\Temp\Test-ODBCConnectionString.log, as defined by the $logfile global variable.  The output will display detailed information which may be helpful when working with a DBA and/or database vendor Support.  It will also display a simplified information section which will provide a clear indication as to the outcome of the test.
 
Important:
 
  • If the test is successful, you may proceed to the final step below.  However, if the test is unsuccessful, you MUST troubleshoot accordingly.  If performed properly, an unsuccessful test via PowerShell will rarely (except in highly unusual circumstances) yield a successful test via PWVA.
  • As explained in the Introduction section of this article, this test simulates a CPM Verify action, utilizing a PowerShell script written such that it directly emulates the same methods that the CPM plugin uses to create a valid ODBC connection to the target database.  The results of the test are external to CyberArk.  All error codes and messages returned are from the ODBC driver and/or target database itself.  It is the responsibility of the customer to work with their DBA and/or database vendor support to troubleshoot, and resolve, the issue.  However, Idira Support may still be able to provide assistance.  Please ensure that the output log file from the test is attached to any ongoing Idira Support case.
 
 
7. Once the test outcome is successful, the connection string must be set on the relevant platform in PVWA.  In PVWA, edit the relevant platform and expand 'Automatic Password Management' -> 'Additional Policy Settings'.  Locate the ConnectionCommand property, clear any existing entry for the corresponding 'value', and enter the properly formatted, syntactically valid, connection string generated from this test.  Review the key points below:
 
    • The ConnectionCommand property must always start with: Driver=
    • All keyword values must be in wildcard format.  For example:
      • %ADDRESS% instead of TargetHost.Domain
      • %USER% instead of SQLAdmin
    • All keyword/value pairs must be terminated with a semicolon (;).
    • If using square brackets ([]) to denote a keyword/value pair as being optional, the terminating semicolon must be included inside the brackets.  For example:
      • [%DATABASE%;] instead of [%DATABASE%];
    • The ODBC driver name MUST be hard coded into the connection string:
      • The driver name is case sensitive.
      • Spaces in the driver name must match, and there cannot be any leading or trailing spaces.
      • To get the exact driver name:
        • On the CPM, open the ODBC Data Source Administrator (32-bit) tool.
        • Select the Drivers tab.
        • Locate the relevant driver (sorted alphabetically by Name).
 

 
Addendum Regarding Microsoft SQL Server Testing
 
When working with SQL Server database accounts, one of the available options for password reconciliation is to use Windows Authentication, otherwise known as Integrated Security.  For more information, please review the following articles from Microsoft:
 
 
When utilizing Integrated Security, Microsoft documentation states that you must append the following keyword/value pair to the ODBC connection string: Trusted_Connection=Yes;.  What this action does is tell the ODBC driver to ignore the specified UID and PWD keys, and to use the Windows-based account instead.  When using the CPM plugin, the ReconcileIsWinAccount platform-level property (set to 'No' by default) must also be set to 'Yes'.  The combination of these two keywords/properties being set to 'Yes' (along with running a Reconcile action) tells the CPM plugin to use Windows authentication when making the connection attempt.
 
While the above process is straight forward when using the plugin, a different process must be followed when running the PowerShell test.  If you append Trusted_Connection=Yes; to the connection string and then run the test, the credentials of the user account running PowerShell will be passed to the ODBC driver.  This will result in an invalid test (unless PowerShell is already running as the reconcile account user).  To achieve a valid test, you MUST run PowerShell as the reconcile account user.  While there are many ways of accomplishing this task, one of the simplest methods to do so is the following:
 
    • On the CPM, click the Start or Search icon.
    • Start typing in Windows PowerShell ISE (x86).
      • Note: Simply typing ISE will suffice.
    • Right-click on Windows PowerShell ISE (x86) and select 'Run as different user'.
    • Enter the credentials of the Windows-based reconcile user account.
      • Note: While this method works for domain-based accounts, it will not work for local Windows accounts.  Unfortunately, is not possible to use this testing method for a local Windows account being used as reconcile account.

NOTE: The 'Run as Administrator' check is bypassed if PowerShell is run using a domain user.

 


Additional Information


Details

Q: How can I test ODBC connection strings outside of CPM?

A: ODBC connection strings can be tested easily with PowerShell.
  1. On the CPM server, Launch "Windows PowerShell ISE (x86)"
    ***Note: this must be the x86 version in order to use the same 32-bit driver that CPM will use***
  2. In the code window (white by default), not the console section, copy and past the following code.

    Function Test-ODBCConnection {
        [CmdletBinding()]
        param(
            [Parameter(Mandatory=$True, HelpMessage='Connection string for ODBC connection')]
            [string]$connectionstring
        )
        $conn = new-object system.data.odbc.odbcconnection
        $conn.connectionstring = $connectionstring

        try {
            $conn.open()
            if ($conn.State -eq 'Open') {
                $conn.Close()
                Write-Host "Connection Opened: $true" -ForegroundColor Green
            }
            else {
                Write-Host "Connection Opened: $false" -ForegroundColor Yellow
            }
        } catch {
            Write-Host $_.Exception.Message -ForegroundColor Yellow
        }
    }

    cls
    $connectionstring = 
    'Driver={Oracle in instantclient_12_2};Dbq=<address>:<port>/<database>;Uid=<username>;Pwd=<password>;'
    Test-ODBCConnection -connectionstring $connectionstring

  3. Update the <variables> in $connectionstring, or completely change the $connectionstring for the desired test.
  4. Press F5, or the Green Play button in Windows PowerShell ISE (x86) to execute the script
Expected Results:
If Successful, Connection Opened will be True and in Green:
Connection Opened: True
If not Successful, a failure and error will be displayed in Yellow
Exception calling "Open" with "0" argument(s): "ERROR [28000] [Oracle][ODBC][Ora]ORA-01017: invalid username/password; logon denied
ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
ERROR [28000] [Oracle][ODBC][Ora]ORA-01017: invalid username/password; logon denied



Actions
  • Print
  • Copy Link

    https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA1hj00000010POCAY&lang=en_US&refURL=http%3A%2F%2Fknowledgebase.paloaltonetworks.com%2FKCSArticleDetail