1 // connect to the DATA SOURCE with the connection string " DSN=mycsql;MODE=csql;SERVER=127.0.0.1;PORT=5678;"
2 // close the connection and call execute, it should fail.
11 //*************************************************************************
13 inline void checkrc(int rc
,int line
)
17 printf("ERROR %d at line %d\n",rc
,line
);
22 //*************************************************************************
30 SQLSMALLINT outstrlen
;
32 // Aloocate an environment handle
33 ret
=SQLAllocHandle(SQL_HANDLE_ENV
,SQL_NULL_HANDLE
,&env
);
34 checkrc(ret
,__LINE__
);
36 //we need odbc3 support
37 SQLSetEnvAttr(env
,SQL_ATTR_ODBC_VERSION
,(void*)SQL_OV_ODBC3
,0);
39 //ALLOCATE A Connection handle
40 ret
= SQLAllocHandle(SQL_HANDLE_DBC
,env
,&dbc
);
41 checkrc(ret
,__LINE__
);
43 // connect to the DSN mydsn
44 ret
= SQLConnect (dbc
,
45 (SQLCHAR
*) "DSN=mycsql;MODE=csql;SERVER=127.0.0.1;PORT=5678;", (SQLSMALLINT
) strlen ("DSN=mycsql;MODE=csql;SERVER=127.0.0.1;PORT=5678;"),
47 (SQLSMALLINT
) strlen ("root"),
48 (SQLCHAR
*) "manager",
49 (SQLSMALLINT
) strlen (""));
52 if(SQL_SUCCEEDED(ret
))
54 printf("\nConnected to the Data Source..\n");
60 printf("connection failed\n");
61 ret
= SQLFreeHandle(SQL_HANDLE_DBC
,dbc
);
62 checkrc(ret
,__LINE__
);
63 ret
= SQLFreeHandle(SQL_HANDLE_ENV
,env
);
64 checkrc(ret
,__LINE__
);
68 ret
= SQLAllocHandle(SQL_HANDLE_STMT
,dbc
,&stmt
);
69 checkrc(ret
,__LINE__
);
71 SQLCHAR table
[100]="CREATE TABLE EMP(EID INT,SALARY INT)";
73 ret
= SQLPrepare(stmt
,table
,SQL_NTS
);
74 checkrc(ret
,__LINE__
);
76 ret
= SQLDisconnect(dbc
);
77 checkrc(ret
,__LINE__
);
79 //AFTER CLOSE THE CONNECTION ,CALL execute
81 ret
= SQLExecute(stmt
);
84 printf("After closing the connection, Execution failed\n");
87 ret
= SQLFreeHandle(SQL_HANDLE_DBC
,dbc
);
88 checkrc(ret
,__LINE__
);
90 ret
= SQLFreeHandle(SQL_HANDLE_ENV
,env
);
91 checkrc(ret
,__LINE__
);
93 if(rettype
==0)return 1;