Connecting Tech Pros Worldwide Forums | Help | Site Map

Obtaining parameter MAX_CONNECTIONS through the API

P
Guest
 
Posts: n/a
#1: Apr 21 '06
Hi,

I'm trying to acquire the parameter MAX_CONNECTIONS by using the API.
The following is the code segment I used:

struct sqlfupd paramItem[5];
paramItem[0].token = SQLF_DBTN_MAX_CONNECTIONS;
paramItem[0].ptrvalue = (char *)malloc(sizeof(int));
sqlfddb(dbName, 1, paramItem, &db2ConnArea);
printf("----------------- STAT =============== %d \n", *(int
*)paramItem[0].ptrvalue);

When I compiled that, I got the following error:

`SQLF_DBTN_MAX_CONNECTIONS' undeclared (first use in this function)

When I tried to obtain the following parameters, as per the example
found on http://webdocs.caspur.it/ibm/udb-6.1...c/d_dbcofc.htm, I
was able to do so:
SQLF_DBTN_LOCKLIST, SQLF_DBTN_BUFF_PAGE, SQLF_DBTN_MAXFILOP,
SQLF_DBTN_SOFTMAX, SQLF_DBTN_LOGPATH.

What was wrong in my attempt?

Thanks


tuarek
Guest
 
Posts: n/a
#2: Apr 23 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


Hi,

It is really weird.

Have you checked the sqlutil.h file? Does "SQLF_DBTN_MAX_CONNECTIONS"
exist in this file?

BTW: It may not solve your problem but you can avoid the compilation
error by using the corresponding constant value 802 instead. Please
refer to

http://publib.boulder.ibm.com/infoce...d/r0008190.htm

regards,

tuarek

P
Guest
 
Posts: n/a
#3: Apr 24 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


Hi tuarek,

Thanks for the reply. I was looking at sqlutil.h and I found the
following entries:

#define SQLF_KTN_DF_ENCRYPT_LIST 801
#define SQLF_KTN_MAX_CONNECTIONS 802

I tried googling for SQLF_KTN_MAX_CONNECTIONS but it didn't give me any
results.

I tried giving it 802 as you've suggested but it returned 0, which was
not correct.

Any idea?

Thanks

Knut Stolze
Guest
 
Posts: n/a
#4: Apr 24 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


P wrote:
[color=blue]
> Hi,
>
> I'm trying to acquire the parameter MAX_CONNECTIONS by using the API.
> The following is the code segment I used:
>
> struct sqlfupd paramItem[5];
> paramItem[0].token = SQLF_DBTN_MAX_CONNECTIONS;
> paramItem[0].ptrvalue = (char *)malloc(sizeof(int));[/color]

You should check here that the memory allocation was successful. Otherwise,
your program could just crash here with a segfault.
[color=blue]
> sqlfddb(dbName, 1, paramItem, &db2ConnArea);[/color]

You should use the "db2CfgGet" API that is provided since version 8:
http://publib.boulder.ibm.com/infoce...n/r0008855.htm
[color=blue]
> printf("----------------- STAT =============== %d \n", *(int
> *)paramItem[0].ptrvalue);
>
> When I compiled that, I got the following error:
>
> `SQLF_DBTN_MAX_CONNECTIONS' undeclared (first use in this function)
>
> When I tried to obtain the following parameters, as per the example
> found on http://webdocs.caspur.it/ibm/udb-6.1...c/d_dbcofc.htm, I
> was able to do so:
> SQLF_DBTN_LOCKLIST, SQLF_DBTN_BUFF_PAGE, SQLF_DBTN_MAXFILOP,
> SQLF_DBTN_SOFTMAX, SQLF_DBTN_LOGPATH.
>
> What was wrong in my attempt?[/color]

You have to include "sqlutil.h" and use the constant
SQLF_KTN_MAX_CONNECTIONS. Btw, I would not recommend that you put the
explicit 802 in your source code. Better fix the real problem.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
tuarek
Guest
 
Posts: n/a
#5: Apr 24 '06

re: Obtaining parameter MAX_CONNECTIONS through the API



I don't have hard evidence but since you haven't found
"SQLF_DBTN_MAX_CONNECTIONS" in your sqlutil.h file: Could there be a
version issue? I mean the db2 version you have may not be supporting
"SQLF_DBTN_MAX_CONNECTIONS" parameter?

Another try?

Logon as dbadmin to the CLP,

set max_connections through

"db2 update dbm cfg using SQLF_DBTN_MAX_CONNECTIONS 100"

or

"update dbm cfg using SQLF_DBTN_MAX_CONNECTIONS 100"

Make sure

"db2 get dbm cfg show detail " or "get dbm cfg show detail" shows your
new value in max_connections constant .

Then try your program with "802" constant. See if it returns 100.

regards,

Mehmet

P
Guest
 
Posts: n/a
#6: Apr 24 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


Hi Knut,

I included "sqlutil.h" and I'm getting 0 when I used the constant
SQLF_KTN_MAX_CONNECTIONS.

What's the difference between SQLF_KTN_MAX_CONNECTIONS and
SQLF_DBTN_MAX_CONNECTIONS? I couldn't find anything about
SQLF_KTN_MAX_CONNECTIONS.

P
Guest
 
Posts: n/a
#7: Apr 24 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


Hi Mehmet,

The version of DB2 I'm using is DB2 v8.1.0.64

I was unable to do
"db2 update dbm cfg using SQLF_DBTN_MAX_CONNECTIONS 100"
But I did manage to change it by doing
"db2 update dbm cfg using MAX_CONNECTIONS 100"

And when I tried to get the parameter, it was still 0. Is
SQLF_DBTN_MAX_CONNECTIONS available for 8.1?

Regards,

P

Knut Stolze
Guest
 
Posts: n/a
#8: Apr 24 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


P wrote:
[color=blue]
> Hi Knut,
>
> I included "sqlutil.h" and I'm getting 0 when I used the constant
> SQLF_KTN_MAX_CONNECTIONS.
>
> What's the difference between SQLF_KTN_MAX_CONNECTIONS and
> SQLF_DBTN_MAX_CONNECTIONS? I couldn't find anything about
> SQLF_KTN_MAX_CONNECTIONS.[/color]

SQLF_DBTN_MAX_CONNECTIONS doesn't exist (any more) and
SQLF_KTN_MAX_CONNECTIONS is defined in sqlutil.h.

Could you possibly provide the complete code that you're using now? Have
you switched to "db2CfgGet"?

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
P
Guest
 
Posts: n/a
#9: Apr 24 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


Hi Knut,

Here's the code. It's based on the example found on
http://publib.boulder.ibm.com/infoce...s-dbinfo-c.htm
db2ConnArea is the sqlca struct.

db2CfgParam cfgParameters[2]; /* to save the DB Config. */
db2Cfg cfgStruct;

/* initialize cfgStruct */
cfgStruct.numItems = 2;
cfgStruct.paramArray = cfgParameters;
cfgStruct.flags = db2CfgDatabase | db2CfgDelayed;
cfgStruct.dbname = dbName;

cfgStruct.paramArray[0].flags = 0;
cfgStruct.paramArray[0].token = SQLF_DBTN_TSM_OWNER;
cfgStruct.paramArray[0].ptrvalue = (char *)malloc(sizeof(char) * 65);
cfgStruct.paramArray[1].flags = 0;
cfgStruct.paramArray[1].token = SQLF_KTN_MAX_CONNECTIONS;
cfgStruct.paramArray[1].ptrvalue = (char *)malloc(sizeof(sqluint32));

db2CfgGet(db2Version810, (void *)&cfgStruct, &db2ConnArea);


printf(" TSM owner = %s\n", cfgParameters[0].ptrvalue);
printf(" maxconn = %u\n",
*(sqluint32 *)(cfgParameters[1].ptrvalue));

Thanks

Knut Stolze
Guest
 
Posts: n/a
#10: Apr 25 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


P wrote:
[color=blue]
> Hi Knut,
>
> Here's the code. It's based on the example found on[/color]

There are a few problems here:
[color=blue]
> db2CfgParam cfgParameters[2]; /* to save the DB Config. */
> db2Cfg cfgStruct;
>
> /* initialize cfgStruct */
> cfgStruct.numItems = 2;
> cfgStruct.paramArray = cfgParameters;
> cfgStruct.flags = db2CfgDatabase | db2CfgDelayed;[/color]

You TSM_OWNER and MAX_CONNECTIONS are DBM CFG parameter and not DB CFG
parameter. This is the reason why you got no results.
[color=blue]
> cfgStruct.dbname = dbName;
>
> cfgStruct.paramArray[0].flags = 0;
> cfgStruct.paramArray[0].token = SQLF_DBTN_TSM_OWNER;
> cfgStruct.paramArray[0].ptrvalue = (char *)malloc(sizeof(char) * 65);
> cfgStruct.paramArray[1].flags = 0;
> cfgStruct.paramArray[1].token = SQLF_KTN_MAX_CONNECTIONS;
> cfgStruct.paramArray[1].ptrvalue = (char *)malloc(sizeof(sqluint32));[/color]

MAX_CONNECTIONS is a signed integer: http://tinyurl.com/mvwk9 If you
interpret it as unsigned, you're bound to get wrong results.
[color=blue]
> db2CfgGet(db2Version810, (void *)&cfgStruct, &db2ConnArea);[/color]

The cast to "void *" is unneccessary.
[color=blue]
> printf(" TSM owner = %s\n", cfgParameters[0].ptrvalue);
> printf(" maxconn = %u\n",
> *(sqluint32 *)(cfgParameters[1].ptrvalue));[/color]

Fixing the above issues should do it. Here is a working example that I
used. It also uses a variable for the result of MAX_CONNECTIONS and, thus,
avoids the ugly cast.
-----------------------------------------------------------------
#include "db2ApiDf.h"
#include <stdio.h>
#include <stdlib.h>

int main()
{
db2CfgParam cfgParameters[2]; /* to save the DB Config. */
db2Cfg cfgStruct;
sqlint32 maxConn = 0;
SQL_API_RC rc = SQL_RC_OK;
struct sqlca sqlca;

memset(&cfgParameters, 0x00, sizeof cfgParameters);
memset(&cfgStruct, 0x00, sizeof cfgStruct);
memset(&sqlca, 0x00, sizeof sqlca);

/* initialize cfgStruct */
cfgStruct.numItems = 2;
cfgStruct.paramArray = cfgParameters;
cfgStruct.flags = db2CfgDatabaseManager | db2CfgDelayed;
cfgStruct.dbname = "test";

cfgStruct.paramArray[0].flags = 0;
cfgStruct.paramArray[0].token = SQLF_DBTN_TSM_OWNER;
cfgStruct.paramArray[0].ptrvalue = (char *)malloc(sizeof(char) * 65);
cfgStruct.paramArray[1].flags = 0;
cfgStruct.paramArray[1].token = SQLF_KTN_MAX_CONNECTIONS;
cfgStruct.paramArray[1].ptrvalue = (char *)&maxConn;

if (!cfgStruct.paramArray[0].ptrvalue) {
free(cfgStruct.paramArray[0].ptrvalue);
fprintf(stderr, "Memory allocation failure.\n");
return EXIT_FAILURE;
}

rc = db2CfgGet(db2Version810, &cfgStruct, &sqlca);
if (rc != SQL_RC_OK) {
fprintf(stderr, "Could not get DB CFG. rc = %d\n", rc);
return EXIT_FAILURE;
}
else if (sqlca.sqlcode != SQL_RC_OK) {
fprintf(stderr, "Could not get DB CFG. SQLCODE = %d\n",
sqlca.sqlcode);
return EXIT_FAILURE;
}

printf(" TSM owner = %s\n", cfgParameters[0].ptrvalue);
printf(" maxconn = %d\n", (int)maxConn);
return EXIT_SUCCESS;
}
-----------------------------------------------------------------

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
P
Guest
 
Posts: n/a
#11: Apr 25 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


Hi Knut,

Thanks! That worked like a charm! :)

P

P
Guest
 
Posts: n/a
#12: Apr 26 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


I have another question. I set MAX_CONNECTIONS back to what it was,
MAX_COORDAGENTS. I did "db2 get dbm cfg" and found out that:

MAX_COORDAGENTS = MAXAGENTS - NUM_INITAGENTS
MAXAGENTS = MAX_COORDAGENTS
NUM_INITAGENTS = 0

By executing the code above, MAX_CONNECTIONS came out to be 4294967295.

Is that correct?

P
Guest
 
Posts: n/a
#13: Apr 26 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


It seems like I experience the problem when the definition of the
parameter is related to another parameter.

For example:
(CATALOGCACHE_SZ) = (MAXAPPLS*4) I'd get "catalog = 4294967295"
(PCKCACHESZ) = (MAXAPPLS*8) I'd get "pkg = 913328"

Is there any way to get around this problem?

Knut Stolze
Guest
 
Posts: n/a
#14: May 2 '06

re: Obtaining parameter MAX_CONNECTIONS through the API


P wrote:
[color=blue]
> I have another question. I set MAX_CONNECTIONS back to what it was,
> MAX_COORDAGENTS. I did "db2 get dbm cfg" and found out that:
>
> MAX_COORDAGENTS = MAXAGENTS - NUM_INITAGENTS
> MAXAGENTS = MAX_COORDAGENTS
> NUM_INITAGENTS = 0
>
> By executing the code above, MAX_CONNECTIONS came out to be 4294967295.
>
> Is that correct?[/color]

It can't be because the maximum signed integer is 2^31 = 2.xxx billion.
You're not considering the sign flag!

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Closed Thread