Creating a Connection from External Parameters in dbForge Studio for MySQL

Creating a Connection from External Parameters in dbForge Studio for MySQL

dbForge Studio for MySQL does not currently support creating or opening connections by passing connection parameters through command-line arguments or Privileged Access Management (PAM) solutions.

The workaround described below allows a connection to be created programmatically by adding the required settings directly to the Windows Registry before launching the application.

Current Limitation

Launching dbForge Studio for MySQL with predefined connection parameters, such as host, port, user name, password, and database, is not supported in the current version of the product.
Info
Support for this functionality is planned for future releases.

Workaround: Creating a Connection Using PowerShell

Connection settings, including the encrypted password, are stored in the Windows Registry under the following key:

HKEY_CURRENT_USER\Software\Devart\dbForge Common Settings\Connections\MySQL

A connection can be created programmatically by populating this registry key before starting dbForge Studio for MySQL.

Step 1. Remove Existing Connections
  1. Open dbForge Studio for MySQL and remove all existing connections from Database Explorer. (If necessary, Export Settings beforehand.)
  2. Close the application after removing the connections.


Step 2. Clean Up the Registry
  1. Open the following registry key: HKEY_CURRENT_USER\Software\Devart\dbForge Common Settings\Connections\MySQL
  2. Make sure it does not contain any subkeys. If subkeys are present, remove them.


Step 3. Run the PowerShell Script

Run the following PowerShell script and provide the required parameters:
  1. host
  2. port
  3. user
  4. password
  5. database

Quote
exmple_code_file.ps1

# Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
$host_name = Read-Host "Please enter a host"
$port = Read-Host "Please enter a port"
$database = Read-Host "Please enter a database"
$user = Read-Host "Please enter a user"
$password = Read-Host "Please enter a password"

# Path to Devart.Shell.Core.dll
$dllPath = "C:\Program Files\Devart\dbForge Studio for MySQL\Devart.Shell.Core.dll"

Add-Type -Path $dllPath
$encryptedPassword = [Devart.Shell.Common.Utils.MiscUtils]::EncodeString($password)
$ConnectionString = "User Id=" + $user + ";Host=" + $host_name + ";Port=" + $port + ";Database=" + $database
$RegConnectionMySQLFolder = "HKCU:\SOFTWARE\Devart\dbForge Common Settings\Connections\MySQL\"
$connection_name = $database + "." + $host_name + ":" + $port
$n = 0

New-Item -Path $RegConnectionMySQLFolder -Name $n
$RegConnectionMySQL_n = $RegConnectionMySQLFolder + $n
New-ItemProperty -Path $RegConnectionMySQL_n -Name "ConnectionString" -Value $ConnectionString -PropertyType "String"
New-ItemProperty -Path $RegConnectionMySQL_n -Name "Database" -Value "59f90733-4d68-4fdf-82a7-f0fcbf5460aa"
New-ItemProperty -Path $RegConnectionMySQL_n -Name "Name" -Value $connection_name
New-ItemProperty -Path $RegConnectionMySQL_n -Name "Password" -Value $encryptedPassword -PropertyType Binary

As a result, dbForge Studio for MySQL should create a connection with a saved password.


Step 4. Launch dbForge Studio for MySQL
  1. Start dbForge Studio for MySQL.
  2. The newly created connection will appear in Database Explorer and can be opened in the usual way.


Step 5. Click Open Connection to connect to the server.

Alternative Approach: Transferring a Connection Between Machines

An existing connection can also be transferred from one machine to another.
  1. Create the connection through the dbForge Studio for MySQL UI on the source machine.
  2. Open the following registry key: HKEY_CURRENT_USER\Software\Devart\dbForge Common Settings\Connections\MySQL
  3. Locate the required connection and export it to a .reg file.
  4. Copy the exported file to the target machine.
  5. Import the registry file by running: reg import file.reg
After the import is completed, the connection becomes available in dbForge Studio for MySQL on the target machine.