[jcifs] jTDS + jCIFS works!

Michael B Allen mba2000 at ioplex.com
Wed Jul 21 23:55:20 GMT 2004


David D. Kilzer said:
> On Tue, Jul 20, 2004 at 12:59:43AM -0400, Michael B Allen wrote:
>
>> On Mon, 19 Jul 2004 23:23:35 -0500, David D. Kilzer wrote:
>>
>> > I do have one more question about named pipes, though.  Is there a way
>> > to set a connection timeout for them using the current API, or does it
>> > not make any sense to do that?
>>
>> Even though Java's IO model doesn't really support the concept of a
>> timeout on a read, if the behavior of TDS is observed to use transaction
>> timeouts that might be necessary to properly emulate the protocol. We
>> don't currently support transaction timeouts because there is no
>> generic interface for transactions but we might be able to expose it
>> in TransactNamedPipeInputStream or somewhere else. If you have a packet
>> capture that shows timeouts being used in some fashion and for practical
>> purposes think it's better to emulate that behavior then I'll look at
>> the issue closer.
>
> Here's the situation I'm trying to resolve:  The jTDS driver must
> implement java.sql.Statement.setQueryTimeout(int seconds).
>
> The current implementation for connecting to SQL Server via TCP/IP is to
> set java.net.Socket.setSoTimeout(seconds * 1000).  When a
> SocketTimeoutException (which extends InterruptedIOException) is thrown,
> jTDS catches it and cancels the connection.

That is a very wrong way to do it. The soTimeout experation is
recalculated with each request. So multiplexing requests from different
callers will result in the timeout not timeing out.

First, you need to determine how to indicate to the server what the
timeout is. Most likely there is TDS protocol support for specifying the
timeout explicitly. You need to determine what that field and utilize it.

If by some strange occurance there is no such capability aside from
encouraging you to dump TDS and use Oracle you should then try to use SMB
Transactions such as CallNamedPipe and TransactNamedPipe as SMB
Transactions support a timeout. If the TDS connection does not operate
properly using these operations or ignores a timeout, aside from strongly
encouraging you to switch to another database, you might look at the SMB
Read/Write RAW commands as they too support a timeout. If again, that is
proven not to work with TDS then my question to you is how does one
indicate to the server that the query should be cancelled? Is just closing
the socket sufficient? In this last case you could simply run a watchdog
thread service that accepts streams and wakes up after the timeout period
has expired and calls close() on it.

Mike


More information about the jcifs mailing list