patternsqlMinor
Setting connection properties (application_name) for Postgres connections
Viewed 0 times
postgrespropertiesapplication_namesettingforconnectionsconnection
Problem
I want to attach an application name to my connection like PgAdmin does here:
(Query in text form:
My connections are created this way (here in VBA):
Where that DSN is created by:
Database,Server IP, User Name, Password, Port)
I could not figure out how to add the
I tried adding this in various places in my VBA code, but it didn't work:
Where do I enter/set the
I know I can set the setting if I use a standard plain text connection string, but I cannot do that for security reasons. I have to use a DSN.
Non-VBA answers very welcome!
(Query in text form:
select pid,query,wait_event,state,* from pg_stat_activity;)My connections are created this way (here in VBA):
Dim cnDB As New ADODB.Connection
cnDB.Open "PostgreSQLDsnHere"Where that DSN is created by:
- for 32 bit: go here:
%WINDIR%\SysWOW64\odbcad32.exe
- for 64 bit: go here:
%windir%\system32\odbcad32.exe
- Go to the System DSN tab and enter the information (Data Source,
Database,Server IP, User Name, Password, Port)
I could not figure out how to add the
application_name in this context/connection setup (using a DSN).I tried adding this in various places in my VBA code, but it didn't work:
cnDB.Properties("ApplicationName") = "testing"Where do I enter/set the
application_name?I know I can set the setting if I use a standard plain text connection string, but I cannot do that for security reasons. I have to use a DSN.
Non-VBA answers very welcome!
Solution
If you can't configure it via the DSN itself, you can always have your connection establishing subroutine set the application name by executing a SQL command on the connection before it hands that connection back to the caller:
In VBScript, this looks like
set application_name to 'my application name';In VBScript, this looks like
dim cn
set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "DSN=PostgreSQL35WDsnHere"
cn.open
cn.execute("set application_name to 'my_application_name';")Code Snippets
set application_name to 'my application name';dim cn
set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "DSN=PostgreSQL35WDsnHere"
cn.open
cn.execute("set application_name to 'my_application_name';")Context
StackExchange Database Administrators Q#184758, answer score: 4
Revisions (0)
No revisions yet.