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