Unix Technical Forum

Obtaining parameter MAX_CONNECTIONS through the API

This is a discussion on Obtaining parameter MAX_CONNECTIONS through the API within the DB2 forums, part of the Database Server Software category; --> Hi, I'm trying to acquire the parameter MAX_CONNECTIONS by using the API. The following is the code segment I ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 07:49 AM
P
 
Posts: n/a
Default Obtaining parameter MAX_CONNECTIONS through the API

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 07:49 AM
tuarek
 
Posts: n/a
Default 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 07:50 AM
P
 
Posts: n/a
Default 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 07:50 AM
Knut Stolze
 
Posts: n/a
Default Re: Obtaining parameter MAX_CONNECTIONS through the API

P wrote:

> 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));


You should check here that the memory allocation was successful. Otherwise,
your program could just crash here with a segfault.

> sqlfddb(dbName, 1, paramItem, &db2ConnArea);


You should use the "db2CfgGet" API that is provided since version 8:
http://publib.boulder.ibm.com/infoce...n/r0008855.htm

> 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?


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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 07:50 AM
tuarek
 
Posts: n/a
Default 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 07:50 AM
P
 
Posts: n/a
Default 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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-27-2008, 07:50 AM
P
 
Posts: n/a
Default 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-27-2008, 07:50 AM
Knut Stolze
 
Posts: n/a
Default Re: Obtaining parameter MAX_CONNECTIONS through the API

P wrote:

> 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.


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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-27-2008, 07:50 AM
P
 
Posts: n/a
Default 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-27-2008, 07:51 AM
Knut Stolze
 
Posts: n/a
Default Re: Obtaining parameter MAX_CONNECTIONS through the API

P wrote:

> Hi Knut,
>
> Here's the code. It's based on the example found on


There are a few problems here:

> db2CfgParam cfgParameters[2]; /* to save the DB Config. */
> db2Cfg cfgStruct;
>
> /* initialize cfgStruct */
> cfgStruct.numItems = 2;
> cfgStruct.paramArray = cfgParameters;
> cfgStruct.flags = db2CfgDatabase | db2CfgDelayed;


You TSM_OWNER and MAX_CONNECTIONS are DBM CFG parameter and not DB CFG
parameter. This is the reason why you got no results.

> 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));


MAX_CONNECTIONS is a signed integer: http://tinyurl.com/mvwk9 If you
interpret it as unsigned, you're bound to get wrong results.

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


The cast to "void *" is unneccessary.

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


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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:37 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com