Hello,
the PgSqlConnection itself doesn't have a Property for ApplicationName.
However when doubleclicking on the component in the designer i can set it in the Initialization group.
I am wondering how I can set the ApplicationName in runtime / code.
I don't want to set it by string replacing / adding the ConnectionString but am looking for a more elegant way.
Also i would like to change the Pooling settings in the same manner.
Thanks.
Set ApplicationName runtime / code
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Set ApplicationName runtime / code
You are right, PgSqlConnection does not have a property to set the ApplicationName connection string parameter, because this parameter must be set before opening a connection. After a connection is opened, this parameter can be set only via the connection string. The connection will be closed after changing a connection string. The same is true for the Pooling connection string parameter.
Re: Set ApplicationName runtime / code
I bought dotConnect for Postgres Professional and looked at the setter for the other properties of PgSqlConnection.
I tried creating a descendant component of PgSqlConnection and access the ApplicationName and Pooling with it.
However i do not have access to the internal classes.
Is it possible to access the classes PgSqlConnectionOptions and ConnectionOptions from an inherited component?
,
I tried creating a descendant component of PgSqlConnection and access the ApplicationName and Pooling with it.
However i do not have access to the internal classes.
Code: Select all
public bool ApplicationName
{
get
{
PgSqlConnectionOptions connectionOptions = this.ConnectionOptions as PgSqlConnectionOptions;
if (connectionOptions == null)
return false;
return connectionOptions.Pooling;
}
set
{
PgSqlConnectionOptions connectionOptions = this.ConnectionOptions as PgSqlConnectionOptions;
if (connectionOptions == null)
return;
connectionOptions.Pooling = value;
}
}
Is it possible to access the classes PgSqlConnectionOptions and ConnectionOptions from an inherited component?
,
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Set ApplicationName runtime / code
There is no possibility to get access to the PgSqlConnectionOptions class, cause it is a private class. Besides, it’s pointless, because changing its property value won’t lead to SET APPLICATION_NAME execution, because this action is performed when a connection opens.chris901 wrote:Is it possible to access the classes PgSqlConnectionOptions and ConnectionOptions from an inherited component?
You can implement the ApplicationName property by executing the "SET APPLICATION_NAME" and "SHOW APPLICATION_NAME" statements
Here is an example of code, implementing it:
Code: Select all
public string ApplicationName
{
get
{
PgSqlCommand command = this.CreateCommand();
command.CommandText = "SHOW application_name";
return (string)command.ExecuteScalar();
}
set
{
PgSqlCommand command = this.CreateCommand();
command.CommandText = "SET APPLICATION_NAME = '" + value + "'";
command.ExecuteNonQuery();
}
}
Code: Select all
public bool Pooling
{
get
{
PgSqlConnectionStringBuilder sb = new PgSqlConnectionStringBuilder(this.ConnectionString);
return sb.Pooling;
}
set
{
PgSqlConnectionStringBuilder sb = new PgSqlConnectionStringBuilder(this.ConnectionString);
sb.Pooling = value;
this.ConnectionString = sb.ConnectionString;
}
}
Re: Set ApplicationName runtime / code
Thanks, I was looking for something like this.