[英]nodejs connect mssql by using node-mssql
I try to use node-mssql( https://github.com/patriksimek/node-mssql/issues ) to connect mssql. 我尝试使用node-mssql( https://github.com/patriksimek/node-mssql/issues )连接mssql。 Here is my config:
这是我的配置:
export class Config {
static db = {
server: ...,
user: ....,
password: ....,
database:...,
}
}
Here is my connection code 这是我的连接代码
sql.connect(Config).then(function(){
new sql.Request().query('SELECT * FROM ABC_2016.dbo.device') .
.then(recordset=>console.log(recordset))
.catch(err =>console.log(err));
Here is my error: (intermediate value).query(...).then is not a function. 这是我的错误:(中间值).query(...)。然后不是函数。
I have no idea why this happen!! 我不知道为什么会这样!
Somebody helps me! 有人帮我!
try using the multiconnection method ... 尝试使用多连接方法...
it's like this : 就像这样 :
var conn1 = new sql.Connection(config, function(error){
if(error){
console.log(error)
} else {
var request = new sql.Request(conn1);
request
.input('project_id', sql.Int,project_id)
.query('SELECT * from TableName WHERE [project_id] = @project_id ORDER BY [id] ')
.then(function(data) {
console.log(data)
}).catch(function(error) {
console.log(error);
});
}
});
Try the following method 尝试以下方法
var webconfig = {
user: 'login',
password: 'sa@123',
server: 'localhost',
database: 'TestDB',
options: {
encrypt: false // Use this if you're on Windows Azure
}
}
var express = require('express');
var sql = require('mssql');
var http = require('http');
var app = express();
var port = process.env.PORT || 8000;
var connection = new sql.Connection(webconfig, function(err) {
var request = new sql.Request(connection);
request.query('select * from Users', function(err, recordset) {
if(err) // ... error checks
console.log('Database connection error');
console.dir("User Data: "+recordset);
});
});
app.listen(port);
console.log(port+' is the magic port');
or visit here https://nodejsbeginersprograms.blogspot.in/2017/02/nodejs-basic-tutorial-with-mssql.html 或访问此处https://nodejsbeginersprograms.blogspot.in/2017/02/nodejs-basic-tutorial-with-mssql.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.