on 01-31-2006 6:11 PM
Hi,
I have created a stateless sessionbean with the intension to connect to the default SAP database by JDBC. Therefore I have created 3 project: a dictionairy project, a enterprise java bean project and a j2ee application project. Within the j2ee application project I have created a datasource alias:
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data-source-aliases SYSTEM "data-source-aliases.dtd">
<data-source-aliases>
<aliases>
<data-source-name>${com.sap.datasource.default}</data-source-name>
<alias>UNIQEMA_CONTACT_US</alias>
</aliases>
</data-source-aliases>
And in the ejb module project I have created also a reference to the datasource:
<resource-ref>
<res-ref-name>UNIQEMA_CONTACT_US</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
I have also created the following create method in the ejb :
public void ejbCreate() throws CreateException {
try {
// Class.forName("com.sap.dbtech.jdbc.DriverSapDB");
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/UNIQEMA_CONTACT_US");
conn = ds.getConnection();
} catch (Exception e) {
throw new CreateException("e.getMessage");
}
}
But when the ejb excutes the ds.getConnection() I got the following error:
com.sap.engine.services.connector.exceptions.BaseResourceException: Cannot get connection. Reason: the thread of component "ejbContexts/sap.com/com.atosorigin.uniqema.contactus.appl/uniqema_contact_us_country" in application "sap.com/com.atosorigin.uniqema.contactus.appl" is currently associated with a restricted resource set and it is not allowed to get connection within it.
Please can someone say what I have done wrong a which feature I have forgotten to set.
regards,
Sander Valkenburg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sander Valkenburg ,
just try DataSource ds = (DataSource) ctx.lookup("jdbc/UNIQEMA_CONTACT_US"); or UNIQEMA_CONTACT_US alone as the look up string.
regards
Kishor Gopinathan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sander,
another note on using DS connections:
1. connection as you may know are scarce resources, meant to be shared among apps. Storing a connection in a instance variable of a bean is not a good idea for another reason to: the database times out connections too!
2. proper usage would be something like this
Connection conn = null;
try {
// acquire conn.
conn = ds.getConnection();
// do something with it
..
} catch( ..) {
...
} finally {
// give conn back to pool
try { if () conn.close(); } catch(Exception e) {}
}
Regards
Gregor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sander,
following suggestion:
1. write a lazy initializer/getter for your DS connection, named say, getLazyDs()
2. call getLazyDs() in one of your EJB's API methods
3. if the call in 2 succeeds, you are done, else there are issues either with the alias definition or reference.
Regards
Gregor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.