make 'sendBulkCopyCommand()' throw exception
@@ -1567,6 +1567,10 @@ public class SQLServerBulkCopy implements java.lang.AutoCloseable {
}
}
catch (SQLServerException ex) {
+ if (null == tdsWriter) {
+ tdsWriter = command.getTDSWriter();
+ }
+
// Close the TDS packet before handling the exception
writePacketDataDone(tdsWriter);
@@ -1580,6 +1584,10 @@ public class SQLServerBulkCopy implements java.lang.AutoCloseable {
throw ex;
}
finally {
+ if (null == tdsWriter) {
+ tdsWriter = command.getTDSWriter();
+ }
+
// reset the cryptoMeta in IOBuffer
tdsWriter.setCryptoMetaData(null);
}
@@ -1604,11 +1612,9 @@ public class SQLServerBulkCopy implements java.lang.AutoCloseable {
return moreDataAvailable;
}
- private TDSWriter sendBulkCopyCommand(TDSCommand command) {
+ private TDSWriter sendBulkCopyCommand(TDSCommand command) throws SQLServerException {
// Create and send the initial command for bulk copy ("INSERT BULK ...").
- TDSWriter tdsWriter = null;
- try {
- tdsWriter = command.startRequest(TDS.PKT_QUERY);
+ TDSWriter tdsWriter = command.startRequest(TDS.PKT_QUERY);
String bulkCmd = createInsertBulkCommand(tdsWriter);
tdsWriter.writeString(bulkCmd);
TDSParser.parse(command.startResponse(), command.getLogContext());
@@ -1618,10 +1624,6 @@ public class SQLServerBulkCopy implements java.lang.AutoCloseable {
// Write the COLUMNMETADATA token in the stream.
writeColumnMetaData(tdsWriter);
- }
- catch (SQLServerException e) {
- return tdsWriter;
- }
return tdsWriter;
}
