在嘗試查看幾十個示例並閱讀大多數文檔並嘗試許多不同變體並更改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