The following example calls JagCmGetConnection to obtain a connection that has a user name of “myrtle,” has a password of “secret,” connects to the server “tsingtao,” and uses Client-Library:
#include <ctpublic.h> #include <jagpublic.h> CS_RETCODE ret; CS_CONNECTION *connection; JagCmCache cache;
/* ** Obtain a connection. */ cache = NULL; ret = JagCmGetConnection (&cache, “myrtle”, “secret”, “tsingtao”, “CTLIB_110”,(SQLPOINTER *)&connection, JAG_CM_FORCE); if (ret != CS_SUCCEED) { ... log the error ... }
... code that uses the connection goes here ...
ret = JagCmReleaseConnection (&cache, “myrtle”,“secret”,“tsingtao”, “CTLIB_110”, (SQLPOINTER)connection, JAG_CM_UNUSED); if (ret != CS_SUCCEED) { ... log the error ... }
In the example, the call to JagCmGetConnection looks for a cache that includes matching values for the user name (“myrtle”), password (“secret”), and server name (“tsingtao”) and that uses Client-Library. The last parameter, opt, is passed as JAG_CM_FORCE to indicate that the call should open a new, uncached connection if no cached connection is available. JagCmReleaseConnection releases control of the connection: a connection that was taken from a cache is returned to that cache; an uncached connection is closed and deallocated.
Note that JagCmGetConnection attempts to open a connection even when no matching cache is configured. In this case, JagCmGetConnection attempts to create a new, uncached connection using the specified values.
In this example, JagCmGetConnection and JagCmReleaseConnection return Client-Library return codes since both calls use “CTLIB_110” for the con_lib parameter.
You can call JagCmGetCachebyName rather than JagCmGetCachebyUser. To see an example, see the reference page for JagCmGetCachebyName in the EAServer API Reference.
Copyright © 2005. Sybase Inc. All rights reserved. |