-
Notifications
You must be signed in to change notification settings - Fork 444
Closed
Labels
Description
I have a table on an Azure SQL Database.
CREATE TABLE [dbo].[Owner](
[OwnerId] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Name] [varchar](50) NOT NULL,
[Signature] [varchar](max) NULL
)
I tried to insert very long string to the Signature column. If the packetSize is not set to 16384 or higher, I got the following exception:
ConnectionError: Connection lost - write ECONNRESET
at ConnectionError (C:\work\GitRepos\tedious-test\node_modules\tedious\lib\errors.js:13:12)
at Connection.socketError (C:\work\GitRepos\tedious-test\node_modules\tedious\lib\connection.js:1187:26)
at Socket.<anonymous> (C:\work\GitRepos\tedious-test\node_modules\tedious\lib\connection.js:1032:14)
at Socket.emit (events.js:205:15)
at errorOrDestroy (internal/streams/destroy.js:107:12)
at onwriteError (_stream_writable.js:438:5)
at onwrite (_stream_writable.js:459:5)
at internal/streams/destroy.js:49:7
at Socket._destroy (net.js:593:3)
at Socket.destroy (internal/streams/destroy.js:37:8)
Emitted 'error' event at:
at Connection.socketError (C:\work\GitRepos\tedious-test\node_modules\tedious\lib\connection.js:1187:12)
at Socket.<anonymous> (C:\work\GitRepos\tedious-test\node_modules\tedious\lib\connection.js:1032:14)
[... lines matching original stack trace ...]
at Socket.destroy (internal/streams/destroy.js:37:8)
at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:84:12) {
message: 'Connection lost - write ECONNRESET',
code: 'ESOCKET'
}
Below is my simple test program. I use the latest tedious. Also the read operation seems to work fine for long string no matter what the packet size is. Any idea what I did wrong?
var Connection = require('tedious').Connection;
var config = {
server: "myserver.database.windows.net",
options: {
encrypt: true,
database: "<mydb>",
packetSize: 4096,
},
authentication: {
type: "default",
options: {
userName: "<myuser>",
password: "<mypwd>",
}
}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
// executeStatement();
executeInsert();
}
);
var Request = require('tedious').Request;
function executeStatement() {
/* Read a long string, work fine */
request = new Request("select OwnerId, Signature From dbo.Owner Where OwnerId = 36", function(err, rowCount) {
if (err) {
console.log(err);
} else {
console.log(rowCount + ' rows');
}
});
request.on('row', function(columns) {
columns.forEach(function(column) {
console.log(column.value);
});
});
connection.execSql(request);
}
function executeInsert() {
/************************************************
* Insert a long string, not working when
* packetSize = 4096
* If
* packetSize = 16384
* or higher, insertion works fine.
*****************************************************/
let s = '0123456789'.repeat(100000);
request = new Request("Insert into dbo.Owner VALUES ('Rick', '" + s + "')", function(err, rowCount) {
if (err) {
console.log(err);
} else {
console.log(rowCount + ' rows');
}
});
connection.execSql(request);
}