程序如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlca.h>
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR username[20];
VARCHAR password[20];
VARCHAR server[20];
EXEC SQL END DECLARE SECTION; 
void sqlerror(); 
main(){
strcpy((char *)username.arr,"scott");
strcpy((char *)password.arr,"tiger");
strcpy((char *)server.arr,"crmdb");
password.len=strlen(password.arr);
username.len=strlen(username.arr);
server.len=strlen(server.arr);
EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL CONNECT :username IDENTIFIED BY :password USING :server;
printf("ok\n");
exit(0);

void sqlerror()
{
printf("sql connection error!\n");
exit(1);
}
错误信息如下:
-------------------Configuration: Exam01 - Win32 Debug--------------------
Compiling...
test.c
E:\test\pctest\Exam01\test.c(173) : error C2065: 'sqlca' : undeclared identifier
E:\test\pctest\Exam01\test.c(210) : error C2224: left of '.sqlcode' must have struct/union type
Error executing cl.exe.Exam01.exe - 2 error(s), 0 warning(s)