1 /* close the connection and then call commit,it should fail.
3 * AUTHOR : Jitendra Lenka
14 //*************************************************************************
16 inline void checkrc(int rc
,int line
)
20 printf("ERROR %d at line %d\n",rc
,line
);
25 //*************************************************************************
33 SQLSMALLINT outstrlen
;
35 // Aloocate an environment handle
36 ret
=SQLAllocHandle(SQL_HANDLE_ENV
,SQL_NULL_HANDLE
,&env
);
37 checkrc(ret
,__LINE__
);
39 //we need odbc3 support
40 SQLSetEnvAttr(env
,SQL_ATTR_ODBC_VERSION
,(void*)SQL_OV_ODBC3
,0);
42 //ALLOCATE A Connection handle
43 ret
= SQLAllocHandle(SQL_HANDLE_DBC
,env
,&dbc
);
44 checkrc(ret
,__LINE__
);
46 // connect to the DSN mydsn
47 ret
= SQLConnect (dbc
,
48 (SQLCHAR
*) "test", (SQLSMALLINT
) strlen ("test"),
50 (SQLSMALLINT
) strlen ("root"),
51 (SQLCHAR
*) "manager",
52 (SQLSMALLINT
) strlen (""));
55 if(SQL_SUCCEEDED(ret
))
57 printf("\nConnected to the Data Source successfully..\n");
63 printf("error in connection\n");
65 ret
= SQLFreeHandle(SQL_HANDLE_DBC
,dbc
);
66 checkrc(ret
,__LINE__
);
68 ret
= SQLFreeHandle(SQL_HANDLE_ENV
,env
);
69 checkrc(ret
,__LINE__
);
74 ret
= SQLDisconnect(dbc
);
75 checkrc(ret
,__LINE__
);
77 ret
= SQLTransact(env
,dbc
,SQL_COMMIT
);
83 printf("After disconnect,commit failed\n");
85 printf("After disconenct, commit passed\n");
87 ret
= SQLFreeHandle(SQL_HANDLE_DBC
,dbc
);
88 checkrc(ret
,__LINE__
);
90 ret
= SQLFreeHandle(SQL_HANDLE_ENV
,env
);
91 checkrc(ret
,__LINE__
);
92 if (rettype
== 0) return 1;