1 // Connect the DATA SOURCE with the connection string "DSN=mycsql;MODE=csql;SERVER=localhost;PORT=5678;"
2 // close the connection and then call commit,it should fail.
12 //*************************************************************************
14 inline void checkrc(int rc
,int line
)
18 printf("ERROR %d at line %d\n",rc
,line
);
23 //*************************************************************************
31 SQLSMALLINT outstrlen
;
33 // Aloocate an environment handle
34 ret
=SQLAllocHandle(SQL_HANDLE_ENV
,SQL_NULL_HANDLE
,&env
);
35 checkrc(ret
,__LINE__
);
37 //we need odbc3 support
38 SQLSetEnvAttr(env
,SQL_ATTR_ODBC_VERSION
,(void*)SQL_OV_ODBC3
,0);
40 //ALLOCATE A Connection handle
41 ret
= SQLAllocHandle(SQL_HANDLE_DBC
,env
,&dbc
);
42 checkrc(ret
,__LINE__
);
44 // connect to the DSN mydsn
45 ret
= SQLConnect (dbc
,
46 (SQLCHAR
*) "DSN=mycsql;MODE=csql;SERVER=localhost;PORT=5678;", (SQLSMALLINT
) strlen ("DSN=mycsql;MODE=csql;SERVER=localhost;PORT=5678;"),
48 (SQLSMALLINT
) strlen ("root"),
49 (SQLCHAR
*) "manager",
50 (SQLSMALLINT
) strlen (""));
53 if(SQL_SUCCEEDED(ret
))
55 printf("\nConnected to the Data Source successfully..\n");
61 printf("error in connection\n");
63 ret
= SQLFreeHandle(SQL_HANDLE_DBC
,dbc
);
64 checkrc(ret
,__LINE__
);
66 ret
= SQLFreeHandle(SQL_HANDLE_ENV
,env
);
67 checkrc(ret
,__LINE__
);
72 ret
= SQLDisconnect(dbc
);
73 checkrc(ret
,__LINE__
);
75 ret
= SQLTransact(env
,dbc
,SQL_COMMIT
);
81 printf("After disconnect,commit failed\n");
83 printf("After disconenct, commit passed\n");
85 ret
= SQLFreeHandle(SQL_HANDLE_DBC
,dbc
);
86 checkrc(ret
,__LINE__
);
88 ret
= SQLFreeHandle(SQL_HANDLE_ENV
,env
);
89 checkrc(ret
,__LINE__
);
90 if (rettype
== 0) return 1;