'//发布:无法从表中获取数据。
//我的代码
const sql = require('mssql/msnodesqlv8');
const poolPromise = new sql.ConnectionPool({
driver: 'msnodesqlv8',
server: "test.database.windows.net",
user: "username",
password: "password",
database: 'database',
port: 1433,
})
.connect()
.then((pool: any) => {
console.log('Connected to MSSQL')
return pool
})
.catch((err: any) => console.log('Database Connection Failed! Bad Config: ', err))
;
describe('any test', () => {
it('verification', async () => {
try
{
const pool = await poolPromise;
const result = await pool.request()
.query('select * from table where username = "Protractor"');
console.log(result);
}
catch(err)
{
console.log(err);
}
});
});错误发生
13:20:25I/launcher-运行1个WebDriver实例13:20:25I/宿主-使用http://localhost:4444/wd/hub上的selenium服务器开始连接到MSSQL { RequestError:无效列名'Protractor‘。在(C:\Users\automation\node_modules\mssql\lib\msnodesqlv8\request.js:258:21) handleError
在(C:\Users\automation\node_modules\msnodesqlv8\lib\reader.js:37:20) StreamEvents.emit (events.js:189:13)
在(C:\Users\automation\node_modules\msnodesqlv8\lib\reader.js:30:14) Array.forEach ()
在(C:\Users\automation\node_modules\msnodesqlv8\lib\reader.js:209:11) invokeObject.end
在(C:\Users\automation\node_modules\msnodesqlv8\lib\driver.js:183:13) at cppDriver.freeStatement (C:\Users\automation\node_modules\msnodesqlv8\lib\driver.js:163:13) originalError:{ Error: MicrosoftSQL ServerInvalid列名'Protractor‘。sqlstate:'42S22',代码: 207 },名称:'RequestError',编号: 207,状态:'42S22‘}
发布于 2020-10-03 09:14:09
在T中双引号和单引号是不可互换的.
试一试:
const result = await pool.request()
.query(`select * from table where username = 'Protractor'`);或者这个:
const result = await pool.request()
.query('select * from table where username = \'Protractor\'');https://stackoverflow.com/questions/64182258
复制相似问题