tedious
tedious copied to clipboard
writeTypeInfo is not a function
Using:
- "tedious": "^8.3.0",
- "tedious-connection-pool": "^1.0.5"
I wrote code that acquires a connection from a pool and then runs a sql on that connection.
I hooked into the columnMetaData
, doneInProc
and done
events.
I tried using the callstack to look through connection.js
and rpcrequest-payload.js
in order to try to find a workaround however I cannot find any caller for type.writeTypeInfo();
in either of these files.
If I might be doing something wrong, I can share snippets of code.
I did see #722 however I have forgone the use of node-mssql
after seeing the FAQ
Callstack (scrubbed):
project/node_modules/tedious-connection-pool/node_modules/tedious/lib/rpcrequest-payload.js:94
type.writeTypeInfo(buffer, param, options);
^
TypeError: type.writeTypeInfo is not a function
at new RpcRequestPayload (project/node_modules/tedious-connection-pool/node_modules/tedious/lib/rpcrequest-payload.js:94:12)
at Connection.execSql (project/node_modules/tedious-connection-pool/node_modules/tedious/lib/connection.js:883:58)
at Object.connection_pool.acquire [as callback] (project/lib/sqlCn.js:66:28)
at ConnectionPool.setUsed (project/node_modules/tedious-connection-pool/lib/connection-pool.js:216:12)
at Connection.<anonymous> (project/node_modules/tedious-connection-pool/lib/connection-pool.js:110:21)
at emitNone (events.js:106:13)
at Connection.emit (events.js:208:7)
at Connection.processedInitialSql (project/node_modules/tedious-connection-pool/node_modules/tedious/lib/connection.js:822:19)
at Connection.message (project/node_modules/tedious-connection-pool/node_modules/tedious/lib/connection.js:1381:21)
at Connection.dispatchEvent (project/node_modules/tedious-connection-pool/node_modules/tedious/lib/connection.js:672:45)
Hi, @mikeymop, please share snippets of your code with us, so it is easier to understand why this is happening. You mentioned that you cannot find a caller to the function type.writeTypeInfo(). For Tedious 8.3.0, there has been an update that replaces those functions wither an interactable buffer mechanism for handling the request payload. The function call to type.writeTypeInfo(). should not exist. For your situation, seems that you have run into some older version of Tedious code. Could you also double-check the version of the Tedious under you "project/node_modules/tedious-connection-pool/node_modules/tedious/lib", see if some older version is involved from here?
Also keep in mind that you're using tedious-connection-pool
library (which is not actively maintained) and not tedious
.
@IanChokS I don't think it's an issue directly with tedious-connection-pool
, but it might be related to the fact that the connection pool depends on an outdated (and unsupported) version of tedious
. We should probably think about starting to actively maintain it, update it, and even think long-term about integrating it into tedious
proper.
@mikeymop As @MichaelSun90 mentioned, you'll have to provide us a code snippet that makes this error easily reproducible. Otherwise, it's really hard for us to understand what is happening and what needs to be fixed. 🙇♂️
Sure, I am working from a class that contains the following (scrubbed):
function get_connection() {
let poolcfg: tcp.PoolConfig = { min: 1, max: 4, log: true };
let connectioncfg = {
userName: settings.user,
password: settings.password,
server: settings.server
};
return new tcp(poolcfg, connectioncfg);
}
function run_sql(payload?) {
if(payload) {
payload = JSON.parse(payload);
if(payload.sql) { this.query = payload.sql }
}
let query = this.query;
this.connection_pool.acquire((err, connection) => {
if(err) { this.error = err; }
let request = new Request(query, (err, _rowCount) => {
if(err) { this.error = err; }
});
request.on('columnMetadata', (columns) => {
console.log(`columnMetadata fired, got:\n${columns}`);
});
request.on('done', (rowCount, _more, rows) => {
console.log(`Done fired, got ${rowCount} rows:\n${rows}`);
connection.release();
});
request.on('doneProc', (rowCount, _more, _returnStatus, rows) => {
console.log(`doneProc fired, got ${rowCount} rows\n${rows}`);
connection.release();
});
connection.execSql(request);
});
}
this.connection_pool = this.get_connection();
this.connection_pool.on('error', (err) => {
this.error = err;
});
let query = "SELECT TOP (2) FROM [Database].[dbo].[Table]";
run_sql(query);
It looks like tedious-connection-pool
is linked to "tedious@^1.14.0",
and contains it within it's own node_modules
. npm might be pulling the newer version into the module.
I was able to find the callable to the depreciated function in the rpcrequest-payload.js inside of the nested node_modules
folder.
(I'm not very good at English, so this is a machine translation.) I ran into a similar problem. In my application,
- tedious-connection-pool : 1.0.5
- tedious : 9.2.1
However, tedious-connection-pool uses tedious ver 1.14.0. This was the direct cause of the problem. So I reinstalled tedious ver9.2.1 to ver1.14.0. This solved the problem.