PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 4, 2022

[FIXED] How to automatically run some command after connect in DBeaver?

 September 04, 2022     authentication, db2-luw, dbeaver     No comments   

Issue

In DBeaver 22.1.2 I created connection to Db2 v11.5.7.0 database with user1.

Every time to start working with connection I do:

  1. Right click on connection and select SQL Editor | New SQL script.
  2. Then I need to switch user with command: set session_user=user2 and then I execute command.
  3. Now running SQLs as usual.

How to do above three steps automatically after I open new script window (or after connect)?

What I have tried so far?

  • If used right click on connection and Edit Connection there is Connection Settings | Shell Commands, but it looks like those commands are run in separate process and also I can't figure it out how to run above command in it.

Solution

This answer specifically addresses only setting of the special register SESSION_USER following connection. For more general SQL to be run after connecting, a different answer is necessary.

Dbeaver 22.1.2 will allow usage of the specialRegisters jdbc property, which lets you assign SESSION_USER special register, and any other special registers you might need.

Tested with Dbeaver 22.1.2 on Linux, and Db2-LUW 11.5.7.0 on Linux.

The key detail is that the specialRegisters property cannot be specified currently on the Edit Connection > Driver Properties > Advanced driver properties screen. If you try to add the setting here, dbeaver will silently discard the setting .

Instead, to get it to work, it's necessary to append to the database-name field on the Edit connection > Main screen, a colon and the setting and a semicolon. For example suppose your database name is sample, then you would use this value in the database field:

sample:specialRegisters=SESSION_USER=user2;

This works with Db2-LUW as long as the connecting userid has the SETSESSIONUSER privilege for the target authid (which has to be granted in advance by a suitable user).



Answered By - mao
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing