怎么解决A database connection does not exist?
code: 1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sqlenv.h>
5 #include <sqlutil.h>
6 EXEC SQL BEGIN DECLARE SECTION;
7 char dbname[20];
8 char user[20];
9 char pwd[20];
10 EXEC SQL END DECLARE SECTION;
11 int main(){
12 strcpy( dbname,"finger" );
13 strcpy( user,"db2fenc1" );
14 strcpy( pwd,"123" );
15 EXEC SQL INCLUDE SQLCA;
16 EXEC SQL CONNECT TO :dbname USER :user USING :pwd;
17 if( SQLCODE < 0 ){
18 printf( "DB2Connect Error \n");
19 }
20 if(SQLCODE ==0 ){
21 printf( "Connected to database \n ");
22 }
23 return 0;
24 }
~
然后进行预编译: db2 prep db2conn_test.sqc
接下来报错:
LINE MESSAGES FOR db2conn_test.sqc
------ --------------------------------------------------------------------
SQL0060W The "C" precompiler is in progress.
SQL1024N A database connection does not exist.
SQLSTATE=08003
SQL0095N No bind file was created because of previous
errors.
SQL0091W Precompilation or binding was ended with "2"
errors and "0" warnings.
如果在预编译之前进行一下连接操作,预编译就可以通过:db2 connect to finger
难倒一定要这步操作吗?
是不是环境变量哪里需要配置?