在尝试查看几十个示例并阅读大多数文档并尝试许多不同变体并更改SQL Server中的许多设置后,终于崩溃了寻求这个帮助。使用knexjs连接到SQL Server,无法获取连接
我使用与SQL Server接受的完全相同的连接字符串成功连接到带有mssqljs的tblTextKnex,但一段时间以来一直无法使用knexjs。
我得到以下警告和错误:
Knex:warning - calling knex without a tableName is deprecated. Use knex.queryBuilder() instead.
和
Unhandled rejection Error: Unable to acquire a connection
这是我认为应该工作不成功的/有问题的代码。
var knex = require('knex')({
client: 'mssql',
connectionString: "Initial Catalog=TextKnex;Data Source=localhost\\TESTINSTANCE;User ID=my_user_id;Password=my_password;Integrated Security=SSPI;"
});
knex().connection().then(() => {
knex('TextKnex').table('Products')
.select('Products.Price as Price')
.then((product) => {
console.log('log product', product);
console.dir('dir product', product);
logger.info('Query Data: %j', product);
})
});
knex.destroy();
既不是第一个也不是第二个选项为您提供工作,这是考虑到knex.org的状态令人惊讶“连接选项直接传递给适当的数据库客户端来创建连接,并且可能是对象或连接字符串:“ – Urasquirrel
我也尝试将版本从4更改为3.3.0,因为这也为其他人带来了问题。这也不起作用, – Urasquirrel
也在测试文件中使用建议的格式不起作用。 knex =要求( 'knex')({ 方言: 'MSSQL', 连接:{ 用户: “计算机\\ kyles2”, 密码: “p_w”, 服务器: “127.0.0.1”, 数据库: “TextKnex”, port:59438 } – Urasquirrel