By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,924 Members | 1,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,924 IT Pros & Developers. It's quick & easy.

DB2 prep bind needed everytime?

P: n/a
Hi All,

If I am changing the database machine, what should I do not to prep
bind the sqc files everytime.

Because I need to build my application everytime the database is
changed?

Is there any way, to do prep bind with "defined timestamp" or
something which does not require any prep - binding even when the
database is changed.

Help is urgently needed!!

Thanks in Advance
Regards,
Ankit Rawat
M.S.

Oct 4 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
cr************@gmail.com wrote:
Hi All,

If I am changing the database machine, what should I do not to prep
bind the sqc files everytime.

Because I need to build my application everytime the database is
changed?

Is there any way, to do prep bind with "defined timestamp" or
something which does not require any prep - binding even when the
database is changed.
When you precompile your SQC files, you specify the option BIND <bindfile>.
That will generate a so-called bindfile. All you have to do at the target
system is to bind that bind file. The bind step will create the necessary
packages and you don't have to precompile the source code at the target
system again.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Oct 4 '07 #2

P: n/a
cr************@gmail.com wrote:
If I am changing the database machine, what should I do not to prep
bind the sqc files everytime.

Because I need to build my application everytime the database is
changed?

Is there any way, to do prep bind with "defined timestamp" or
something which does not require any prep - binding even when the
database is changed.
You need to distinguish between PREP and BIND.
If you produce a bind file when doing the PREP you can deploy the bind
file with your compiled application.
All DB2 needs to do then is BIND the application against the database.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Oct 5 '07 #3

P: n/a
On Oct 5, 8:01 am, Serge Rielau <srie...@ca.ibm.comwrote:
crack.the.h...@gmail.com wrote:
If I am changing the database machine, what should I do not to prep
bind the sqc files everytime.
Because I need to build my application everytime the database is
changed?
Is there any way, to do prep bind with "defined timestamp" or
something which does not require any prep - binding even when the
database is changed.

You need to distinguish between PREP and BIND.
If you produce a bind file when doing the PREP you can deploy the bind
file with your compiled application.
All DB2 needs to do then is BIND the application against the database.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Thanks man for your kind help, you mean to say I need to build the
application including the .bnd file?

I am now telling you the exact scenario! See suppose I am using a
database named DB1, I have .sqc files containing the sql commands. We
do prep by the following command at the db2 command line:

"db2 prep file1.sqc Version V1.0 bindfile "

then I do bind those .sqc by the following command:

"db2 bind filename.bnd"

Now, suppose we are migrating the application to the new database
named DaB2, do we again need to prep the files because if we do need
then again the new .C files are getting generated and I am bound to
rebuild the application.

Regards,
Ankit R.
M.S

Oct 10 '07 #4

P: n/a
Ankit wrote:
Thanks man for your kind help, you mean to say I need to build the
application including the .bnd file?
You don't "need to" but if you want to deploy the application on a different
system than where it was build, bindfiles are the way to distribute the SQL
statements to the target system. With a bindfile, it is not necessary to
recompile (including precompile) an application at the target system. Just
copy the executables, shared libraries, bindfiles (and whatever else the
application may need) to the system, bind the bindfiles to create the
respective packages in DB2 and then start the application.
I am now telling you the exact scenario! See suppose I am using a
database named DB1, I have .sqc files containing the sql commands. We
do prep by the following command at the db2 command line:

"db2 prep file1.sqc Version V1.0 bindfile "

then I do bind those .sqc by the following command:

"db2 bind filename.bnd"

Now, suppose we are migrating the application to the new database
named DaB2, do we again need to prep the files because if we do need
then again the new .C files are getting generated and I am bound to
rebuild the application.
As I mentioned above: since you don't change the code, there is no need to
precompile anything again. You won't get new .C files and you don't have
to recompile such .C files. (This assumes that you have the same platform
and don't change the actual code, of course.)

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Oct 10 '07 #5

P: n/a
On Oct 10, 5:46 am, Knut Stolze <sto...@de.ibm.comwrote:
Ankit wrote:
Thanks man for your kind help, you mean to say I need to build the
application including the .bnd file?

You don't "need to" but if you want to deploy the application on a different
system than where it was build, bindfiles are the way to distribute the SQL
statements to the target system. With a bindfile, it is not necessary to
recompile (including precompile) an application at the target system. Just
copy the executables, shared libraries, bindfiles (and whatever else the
application may need) to the system, bind the bindfiles to create the
respective packages in DB2 and then start the application.
I am now telling you the exact scenario! See suppose I am using a
database named DB1, I have .sqc files containing the sql commands. We
do prep by the following command at the db2 command line:
"db2 prep file1.sqc Version V1.0 bindfile "
then I do bind those .sqc by the following command:
"db2 bind filename.bnd"
Now, suppose we are migrating the application to the new database
named DaB2, do we again need to prep the files because if we do need
then again the new .C files are getting generated and I am bound to
rebuild the application.

As I mentioned above: since you don't change the code, there is no need to
precompile anything again. You won't get new .C files and you don't have
to recompile such .C files. (This assumes that you have the same platform
and don't change the actual code, of course.)

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Well what about the sqc file connection string?? Of course it would be
change, although I am trying to use system variable yet it is not
allowing me to do so.!!!!!

Sending you the sample code of connection.sqc
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sql.h"
//#include "ibmdadb2.h"

#include "sqlca.h"
#include "sqlenv.h"
#include "sqlcodes.h"
#include "sqlutil.h"
#include "db2ApiDf.h"

char * dname = getenv("DATABASE");
char * username = getenv("USER");
char * password = getenv("PASSWORD");

void Db2connect()
{
EXEC SQL INCLUDE sqlca;
//struct sqlca sqlca;

/* connect to a database */

EXEC SQL CONNECT TO dname USER user USING password;
if (sqlca.sqlcode != 0)
{
MessageBox(0,"Connection Fail","Msg",0);
}
} /* end main */
/************************************end of
sqc*********************************************** ''/

Now the C file is generated looks like:
/********************************C generated code from .sqc
file***************************/
static char sqla_program_id[162] =
{
43,0,65,68,65,74,65,72,67,79,78,78,69,67,84,73,71, 66,99,118,
70,75,75,88,48,49,49,49,49,50,32,32,9,0,83,86,67,8 2,69,80,
79,53,80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0
};

#include "sqladef.h"

static struct sqla_runtime_info sqla_rtinfo =
{{'S','Q','L','A','R','T','I','N'}, sizeof(wchar_t), 0, {' ',' ',' ','
'}};
#line 1 "connection.sqc"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sql.h"
//#include "ibmdadb2.h"

#include "sqlca.h"
#include "sqlenv.h"
#include "sqlcodes.h"
#include "sqlutil.h"
#include "db2ApiDf.h"

char * dname = getenv("DATABASE");
char * username = getenv("USER");
char * password = getenv("PASSWORD");

void Db2connect()
{

/*
EXEC SQL INCLUDE sqlca;
*/

/* SQL Communication Area - SQLCA - structures and constants */
#include "sqlca.h"
struct sqlca sqlca;
#line 26 "connection.sqc"

//struct sqlca sqlca;

/* connect to a database */
/*
EXEC SQL CONNECT TO dname USER username USING password;
*/

{
#line 31 "connection.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 31 "connection.sqc"
sqlaaloc(2,3,1,0L);
{
struct sqla_setd_list sql_setdlist[3];
#line 31 "connection.sqc"
sql_setdlist[0].sqltype = 460; sql_setdlist[0].sqllen = 6;
#line 31 "connection.sqc"
sql_setdlist[0].sqldata = (void*)dname;
#line 31 "connection.sqc"
sql_setdlist[0].sqlind = 0L;
#line 31 "connection.sqc"
sql_setdlist[1].sqltype = 460; sql_setdlist[1].sqllen = 9;
#line 31 "connection.sqc"
sql_setdlist[1].sqldata = (void*)username;
#line 31 "connection.sqc"
sql_setdlist[1].sqlind = 0L;
#line 31 "connection.sqc"
sql_setdlist[2].sqltype = 460; sql_setdlist[2].sqllen = 9;
#line 31 "connection.sqc"
sql_setdlist[2].sqldata = (void*)password;
#line 31 "connection.sqc"
sql_setdlist[2].sqlind = 0L;
#line 31 "connection.sqc"
sqlasetda(2,0,3,sql_setdlist,NULL,0L);
}
#line 31 "connection.sqc"
sqlacall((unsigned short)29,5,2,0,0L);
#line 31 "connection.sqc"
sqlastop(0L);
}

#line 31 "connection.sqc"

if (sqlca.sqlcode != 0) {
MessageBox(0,"Connection Fail","Msg",0);

}
} /* end main */
/*********************end of C code*******************************/

Now, even after I bind connection.bnd to the database 1 and database
2, it only accepts the connection to the first database, not the
second one..

Can i generalise my .C file so that there are no change required. I am
sure my problem is very clear to you.
Thanks in advance!!

Oct 10 '07 #6

P: n/a
Ankit wrote:
Well what about the sqc file connection string?? Of course it would be
change, although I am trying to use system variable yet it is not
allowing me to do so.!!!!!

Sending you the sample code of connection.sqc

char * dname = getenv("DATABASE");
char * username = getenv("USER");
char * password = getenv("PASSWORD");

void Db2connect()
{
/*********************end of C code*******************************/

Now, even after I bind connection.bnd to the database 1 and database
2, it only accepts the connection to the first database, not the
second one..

Can i generalise my .C file so that there are no change required. I am
sure my problem is very clear to you.
If you hard-code database name, user-id and/or password, you have a problem.
You should parameterize your code to read such information either from some
config file (which can easily be adjusted with your favorite editor), or
receive that information via command line parameters.

Besides that, you can use the LEVEL option available for the PRECOMPILE
command to avoid recreating and rebinding a bind file if the code but not
the SQL statements within the code changes. That way, you would only change
the LEVEL if a SQL statement (and, thus, the package) will change. But
then, having the hard-coded connection information requires you to
recompile the code anyways. A new package is not a big deal then.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Oct 10 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.