title: "Stored procedure 'xxx' may be run only in unchained transaction mode." error when calling a procedure from a DataSource, in an EJB context
body: <p>We have a Database in Sybase, which we access from a Java server.</p>
  
  <p>Access to the DB was made directly through the Sybase driver, using <code>DriverManager</code>. It was working correctly, we were able to call our stored procedures.</p>
  
  <p>Recently, we are migrating to an application server (on JBoss 5), and the calls to the database are now made through a JNDI connector, using a <code>DataSource</code>: </p>
  
  <pre><code>Properties ppt = new Properties();
  ppt.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  ppt.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  ppt.put("java.naming.provider.url", "jdbc/sybase");
  
  InitialContext ctx = new InitialContext(ppt);
  DataSource ds = (DataSource) ctx.lookup(AConfig.getInstance().getDatasourceJndiName());
  
  Connection conn = ds.getConnection();
  </code></pre>
  
  <p><em>(The DataSource is configured using the basic settings, from the <a href="http://community.jboss.org/wiki/SetUpASybaseDatasource" rel="nofollow">JBoss example</a>)</em></p>
  
  <p>However, in this setting, several procedures are failing, with this error: </p>
  
  <blockquote>
    <p>"Stored procedure '<strong>**</strong>' may be run
    only in unchained transaction mode."</p>
  </blockquote>
  
  <p>or this kind, for other cases (with the failing command changing): </p>
  
  <blockquote>
    <p>TRUNCATE TABLE command not allowed
    within multi-statement transaction</p>
  </blockquote>
  
  <p>From what I found on Internet, it looks like something in the JBoss or the connector is opening a transaction itself, causing these errors. As such, the diverse solutions I could find for these particular problems are too localized, and it seems like a bigger issue.</p>
  
  <p>Is there a way to prevent this behaviour (assuming that this is the actual problem)?</p>
  
  <hr>
  
  <p><em>My knowledge in this particular field is quite thin, this is new to me. As such, there are probably important details missing to this description. Please indicate me how I can improve this question, what details I can add, if necessary.</em></p>