排序连接和日志记录问题 [英] Sequelize connection and logging issues
问题描述
我正在尝试使用Sequelize与SQL Server 2012数据库连接.当我的连接字符串明显错误时,我看到了ECONN REFUSED消息和超时.现在,按照以下代码,尽管登录成功和失败,但我没有得到任何回应:
I am trying to use Sequelize to connect with a SQL Server 2012 database. When my connection string was clearly wrong, I was seeing ECONN REFUSED messages and timeout. Now, I am not getting any response, despite logging on success and fail, per this code:
import * as Sequelize from 'sequelize';
-- connection string redacted
let seqConn = new Sequelize("mssql://**;Initial Catalog=**;Persist Security Info=True;Integrated Security=SSPI; User ID=**; Password=**")
seqConn
.authenticate()
.then(function(err) {
console.log('Connection has been established successfully.');
})
.catch(function (err) {
console.log('Unable to connect to the database:', err);
});
我以前使用的语法是:
let seqConn = new Sequelize("DB", "Username", "Password",
{
dialect: 'mssql',
dialectOptions: {
instanceName: 'dev'
},
host: '**'
};
但是我找不到集成安全性或其他精美的SQL Server设置.
But I couldn't find a setting for integrated security or other fancy SQL Server things.
无论如何,我当前的连接字符串没有错误.但是,这并不是说已建立连接.
Regardless, my current connection string isn't erroring. But also, it is not saying the connection was established.
我尝试将seqConn传递给模型以使用它来检索模型:
I tried passing my seqConn to a model to use it to retrieve a model:
getModel(seqConn): void {
console.log("Getting");
var model = seqConn.define("dbo.Model", {
modelID: Sequelize.INTEGER,
modelNo: Sequelize.INTEGER,
modelName: Sequelize.STRING(50),
modelAge: Sequelize.DATE
});
seqConn.sync().then(function() {
model.findOne()
.then( function (modelRes){
console.log("got a result!?");
console.log(modelRes.get("modelName"));
})
.catch( function (error){
console.log("it didn't work :( ");
});
});
console.log('after getter');
return;
}
我不确定这是否是使用sequelize的正确方法,并且我仍在建立我的项目结构,但是现在我希望看到得到结果"或错误,但是什么都没有记录从then()
或catch()
.之前/之后的吸气剂日志记录得很好.
I'm not confident that this is the right way to use sequelize, and I'm still establishing my project structure, but for now I expect to either see a "got a result" or an error, but nothing is logging here from either the then()
or the catch()
. The before/after getter logs are logging fine.
我已经考虑到连接需要很长时间,但是我的IT部门说他在我们的SQL日志中看到了我成功的连接,并且我之前的超时时间大约是15,000毫秒.
I have considered that it takes a long time to connect, but my IT says that he saw my successful connection in our SQL logs, and previously I was getting timeouts in about 15,000 ms, I think.
推荐答案
通过添加另一个NPM模块解决了该问题:`sequelize-msnodesqlv8'
The problem was solved by including another NPM module: `sequelize-msnodesqlv8'
然后连接到Sequelize的代码如下:
And then the code to connect to Sequelize looked like:
var Sequelize = require('sequelize');
var seqConn = new Sequelize({
dialect: 'mssql',
dialectModulePath: 'sequelize-msnodesqlv8',
dialectOptions: {
connectionString: 'Driver={SQL Server Native Client 11.0};[REDACTED]'
}
});
seqConn
.authenticate()
.then(function(err) {
console.log('Connection has been established successfully.');
})
.catch(function (err) {
console.log('Unable to connect to the database:', err);
});
这篇关于排序连接和日志记录问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!