[英]mssql node, get request returns ReferenceError: request is not defined
working on rest api for my db got this problem 为我的数据库使用REST API时遇到此问题
ReferenceError: request is not defined ReferenceError:请求未定义
right now I have a connection that works, but stuck with how to make rest requests with mssql-node. 现在我有一个可以正常工作的连接,但是仍然无法使用mssql-node发出其余请求。 originally I used mySql db but now have to make it work with mssql. 最初,我使用mySql db,但现在必须使其与mssql一起使用。 after I spent some time I have 2 error types - this one or connection doesn't work if I do connection in app.get 我花了一段时间后,我有2种错误类型-如果我在app.get中进行连接,则此错误类型或连接将不起作用
the way it's set up right now is 现在设置的方式是
const express = require('express')
const sql = require('mssql');
const Connection = require('tedious').Connection;
var config = {
userName: 'user' ,
password: 'pass',
domain: "AD",
server: serversIP,
database: 'test',
port: 2222,
debug: true,
driver: 'tedious',
options: {
database:"test",
instanceName : "instance"
}
}
var connection = new Connection(config);
connection.on('connect', function(err) {
if (err) {
console.log(err);
} else {
console.log("server is connected to DB")
}}
);
app.get("/" , (req, res)=>{
new sql.Request().query(`SELECT * FROM test `, (err, recordset) => {
if (err) {
console.log(err);
return;
}
else {
res.send(JSON.stringify(recordset));
}
});
request.query();
});
what can be the reason for this error? 该错误的原因是什么?
UPDATE 更新
after several small iterations of errors I got an error that connaction isn't specified 经过几次小的错误迭代后,我得到一个错误,未指定联系人
with new function like this 具有这样的新功能
app.get("/getUsers", (req, res)=>{
sql.connect(config, function (err) {
var request = new sql.Request();
if (err) {
console.log(err);
return;
}
new sql.query(`SELECT * FROM dbo.tblDatabaseUserIDs_lookup `, (err, recordset) => {
console.log("first error msg");
if (err) {
console.log(err);
return;
}
else {
console.log("second error msg");
res.send(JSON.stringify(recordset));
}
});
console.log("3rd error msg");
//req.query();
});
});
my new error msg is 我的新错误消息是
var bufferLength = 64 + domain.length * 2 + username.length * 2 + lm v2len + ntlmv2len + 8 + 8 + 8 + 4 + server_data.length + 4; var bufferLength = 64 + domain.length * 2 + username.length * 2 + lm v2len + ntlmv2len + 8 + 8 + 8 + 4 + server_data.length + 4;
TypeError: Cannot read property 'length' of undefined TypeError:无法读取未定义的属性“ length”
thought that it can be due to first connection function so i replaced 认为这可能是由于首次连接功能造成的,所以我更换了
sql.connect(config, function (err) {
var request = new sql.Request();
if (err) {
console.log(err);
return;
}
with 与
...connection.callProcedure(function (err) {
new sql.query(`SELECT * ....
and got this 并得到了
TypeError: request.validateParameters is not a function TypeError:request.validateParameters不是函数
but with 但随着
connection.commitTransaction
it gives me this one 它给了我这个
(node:15956) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RequestError: No connection is specified for that request. (节点:15956)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):RequestError:未为该请求指定连接。
the fun part that i tried to follow this solution Can't get Node mssql to work properly 我尝试遵循此解决方案的有趣部分无法使Node mssql正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.