How can I test ODBC connection strings outside of CPM?
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
2. On the CPM server, Launch "Windows PowerShell ISE (x86)" as Administrator.
3. In the PowerShell Script Pane (the white section), copy and paste the entire contents from the text file.
-
- 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 <#).
-
- If using an encrypted password, update the
$connectionstringvariable on line 16. - If using a cleartext password, update the
$connectionstringvariable on line 20.
- If using an encrypted password, update the
$connectionstring = ", as well as trailing ", are not altered.%target_address% with the address of the target database server (ensure you remove the surrounding percentage sign (%) characters as well).$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.- 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.
-
- The ConnectionCommand property must always start with:
Driver= - All keyword values must be in wildcard format. For example:
%ADDRESS%instead ofTargetHost.Domain%USER%instead ofSQLAdmin
- 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).
- The ConnectionCommand property must always start with:
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.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?- 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*** - 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 - Update the <variables> in $connectionstring, or completely change the $connectionstring for the desired test.
- 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 deniedERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
ERROR [28000] [Oracle][ODBC][Ora]ORA-01017: invalid username/password; logon denied