---
title: "SQLServerException: DBComms.receive产生的原因"
author: "peter.kong"
date: "2006-12-06T18:12:44Z"
tags: []
slug: "sqlserverexception-dbcomms-receive"
draft: false
lastmod: "2006-12-06T18:12:44Z"
id: 37661
url: "https://peter-kong.iteye.com/blog/37661"
---

SQLServerException: DBComms.receive产生的原因
Filed under: SQL Server — Jet @ 12:05 am
http://www.javatang.com/archives/2006/04/28/053226.html

使用SQLServer2005的JDBC进行SQL Server2000的操作, 程序中使用了多线程的”Worker Thread”模式, 但是在运行的过程中偶尔会产生这样的SQLServerException:

    使用 DBComms.receive 方法期间发生异常。操作:socket closed。上下文:(9) , IO:897a
    9, Dbc:null]。PktNum:0。TotalReceived:0。PktSize:4,096。

后来查了一些有限的资料, 终于知道了原因所在. 原来是因为程序中的代码是非线程安全的, JDBC对象是不能被多个线程共用的. 产生这个异常的原因可能是一个线程中Connection正在关闭或Statement正在被重新执行的时候另一个线程正在使用.

    Hi. I suspect it’s your application code (including the dbcp stuff) that may not be threadsafe. Your JDBC objects can’t be shared by multiple threads. I suspect a connection is being closed, or a statement is being re-executed by one thread while another is still using it.
    Joe Weinstein at BEA Systems

参考资料:
http://www.webservertalk.com/archive135-2006-2-1390423.html

This entry was posted on Friday, April 28th, 2006 at 12:05 am and is filed under SQL Server. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.