简体   繁体   English

无法创建交易异常:com.microsoft.sqlserver.jdbc.SQLServerException 登录错误

[英]CannotCreateTransactionException: com.microsoft.sqlserver.jdbc.SQLServerException Login Error

i am using Spring Batch with a Microsoft SQL 2014 Database.我正在使用带有 Microsoft SQL 2014 数据库的 Spring Batch。 It is running on a Tomcat 9.0.16 Server with OpenJDK 11.0.2它在带有 OpenJDK 11.0.2 的 Tomcat 9.0.16 服务器上运行

My Problem is that i get randomly errors in which there is no JDBC Connection possible.我的问题是我收到随机错误,其中没有可能的 JDBC 连接。 There are two Steps defined in the Job: The first one contains the following Tasklet Job 中定义了两个 Step:第一个包含以下 Tasklet

The relevant Code :相关代码:

@Bean
    public Step stepOne() {
        final Tasklet taskletOne = new Tasklet() {
            @Override
            public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {                
                JdbcTemplate cmd = new JdbcTemplate(dataSource);
                maxlsnr = cmd.queryForObject("select max(ID) from dbo.MY TABLE", Integer.class);
                LOG.info("MAX ID: " + maxlsnr);
                return RepeatStatus.FINISHED;
            }
        };
        TaskletStepBuilder stepBuilder = stepBuilderFactory.get("QUERY FOR INTEGER")
                .tasklet(taskletOne);
        stepBuilder.listener(taskletOne);
        return stepBuilder.build();
    }

The second Step contains a Chunk based, FlatfileItemReader (read CSV), Processor (Filter item based on # from Step1) and an Itemwriter(Insert into DB).第二步包含一个基于块的 FlatfileItemReader(读取 CSV)、处理器(基于 # 来自 Step1 的过滤项目)和一个 Itemwriter(插入数据库)。

We randomly get the following Error:我们随机得到以下错误:

 2019-03-04 09:14:01.607 ERROR 497 --- [io-8080-exec-92] o.s.b.w.servlet.support.ErrorPageFilter  : Forwarding to error page from request [/batch/jobs/myjob] due to exception [Could not open JDBC Connection for transaction; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Fehler bei der Anmeldung für den Benutzer 'xxxx'. ClientConnectionId:ecb4e02c-e40e-4f43-957d-a870e46703fd]
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Fehler bei der Anmeldung für den Benutzer 'xxxx'. ClientConnectionId:ecb4e02c-e40e-4f43-957d-a870e46703fd
        at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:305)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy256.getLastJobExecution(Unknown Source)
        at de.codecentric.batch.web.JobOperationsController.createJobParametersWithIncrementerIfAvailable(JobOperationsController.java:204)
        at de.codecentric.batch.web.JobOperationsController.launch(JobOperationsController.java:182)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:130)
        at org.springframework.boot.web.servlet.support.ErrorPageFilter.access$000(ErrorPageFilter.java:66)
        at org.springframework.boot.web.servlet.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:105)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:117)
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:106)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Fehler bei der Anmeldung für den Benutzer 'xxxx'. ClientConnectionId:ecb4e02c-e40e-4f43-957d-a870e46703fd
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:256)
        at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:258)
        at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:104)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:5028)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3660)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:94)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3619)
        at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2930)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2456)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2103)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1950)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1162)
        at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnectionInternal(SQLServerDataSource.java:1067)
        at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnection(SQLServerDataSource.java:85)
        at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:262)
        ... 80 common frames omitted

The Database shows no Errors and seems to be working without any problems.数据库没有显示任何错误,似乎工作没有任何问题。 I am using the latest MSSQL JDBC Drivers : 7.2.1 All other programs are working just fine with the same user + database.我正在使用最新的 MSSQL JDBC 驱动程序:7.2.1 所有其他程序在使用相同的用户 + 数据库时都可以正常工作。

I already tried it with newly created credentials, but the problem still exists.我已经使用新创建的凭据进行了尝试,但问题仍然存在。

After month without finding a solution i finally managed it to make it work as required.一个月后没有找到解决方案,我终于设法让它按要求工作。

The problem is somewhere in the default Spring Database / Connection Pool management configuration.问题出在默认的 Spring 数据库/连接池管理配置中。 I switched the underlying JDBC Connection Pool to HikariCP and the problem disappeared !我将底层的 JDBC 连接池切换到HikariCP ,问题就消失了!

I added the HikariCP Dependency in my Maven pom.xml and changed my default DataSource to a HikariDataSource.我在我的 Maven pom.xml 中添加了 HikariCP Dependency 并将我的默认数据源更改为 HikariDataSource。

final HikariConfig config = new HikariConfig();
    config.setPoolName(environment.getProperty("datasourcewww.serverName"));
    config.setDataSourceClassName("com.microsoft.sqlserver.jdbc.SQLServerDataSource");
    config.setUsername(userName);
    config.setPassword(password);
    config.addDataSourceProperty("serverName", serverName);

    config.addDataSourceProperty("databaseName", databaseName);
    config.setConnectionTimeout(10000);
    config.setMinimumIdle(10);
    config.setMaximumPoolSize(200);
    config.setIdleTimeout(1800000);

    LOG.info("HikariCP DataSource initialized.");
    return new HikariDataSource(config);

I hope this helps, in case someone does have the same trouble...我希望这会有所帮助,以防有人遇到同样的问题...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.microsoft.sqlserver.jdbc.SQLServerException:用户登录失败 - com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user com.microsoft.sqlserver.jdbc.SQLServerException 与 jpa - com.microsoft.sqlserver.jdbc.SQLServerException with jpa 错误:com.microsoft.sqlserver.jdbc.SQLServerException:索引 2 超出范围 - Error: com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range com.microsoft.sqlserver.jdbc.SQLServerException:'GO'附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'GO' com.microsoft.sqlserver.jdbc.SQLServerException: ')' 附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ')' 如何修复:com.microsoft.sqlserver.jdbc.SQLServerException? - How to fix it: com.microsoft.sqlserver.jdbc.SQLServerException? com.microsoft.sqlserver.jdbc.SQLServerException: 索引 2 超出范围:( - com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range :( com.microsoft.sqlserver.jdbc.SQLServerException:无效的列名称“ xxx” - com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'xxx' com.microsoft.sqlserver.jdbc.sqlserverexception:参数编号1无效 - com.microsoft.sqlserver.jdbc.sqlserverexception: the parameter number 1 is not valid com.microsoft.sqlserver.jdbc.SQLServerException: '=' 附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '='
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM