本文介绍了JDBC set_approle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用prepareCall通过JDBC连接设置应用程序角色.似乎可以正常运行(即,在语法上合理),但是SQL Server 2008返回此错误:

I am trying to set an application role through a JDBC connection using a prepareCall. It seems to work ok (i.e. syntax wise) but SQL server 2008 returns this error:

Application roles can only be activated at the ad hoc level

我不是从存储过程或其他任何东西中触发此操作,而是直接从我的JDBC连接中触发,

I am not firing this from within a stored procedure or anything, just directly from my JDBC connection, as such:

CallableStatement cstmt = con.prepareCall("{call sys.sp_setapprole(?, ?, ?, ?)}");
//setup all the IN and OUT parameters here
cstmt.execute();

对于为什么这种方法无效的任何想法吗?

Any ideas for why this doesn't work?

推荐答案

事实证明,我使用的JDBC驱动程序(Microsoft的JDBC驱动程序)无法关闭准备好的语句"或语句池".因此,发送到数据库的所有内容都包装在sp_prepexec()中,sys.sp_setapprole()检测到该sp_prepexec()并且不喜欢它,因为它无法包装在另一个过程中,必须直接在数据库上单独执行.不幸的是,解决方案是使用另一个JDBC驱动程序.

As it turns out the JDBC driver I was using, Microsoft's JDBC driver, has no way of turning off Prepared Statements or Statement Pooling. So everything that was sent to the database was wrapped in a sp_prepexec() which the sys.sp_setapprole() detected and didn't like as it can't be wrapped inside another procedure and must execute on its own directly on the database. The solution unfortunately is to go with another JDBC driver.

这篇关于JDBC set_approle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 16:30