简体   繁体   English

从 node.js 驱动程序 mssql(繁琐的包装器)连接到 SQL Server Express 版本

[英]Connect to SQL Server Express edition from node.js driver mssql (Tedious wrapper)

TypeError [ERR_INVALID_URL]: Invalid URL:类型错误 [ERR_INVALID_URL]:无效的 URL:
mssql://testuser:testuser@192.168.1.70\SQLEXPRESS/MyTestDB mssql://testuser:testuser@192.168.1.70\SQLEXPRESS/MyTestDB

The node package is: https://www.npmjs.com/package/mssql节点package为: https://www.npmjs.com/package/mssql

As per their Quick Example根据他们的Quick Example

await sql.connect('mssql://username:password@localhost/database')

I am doing this我正在这样做

await sql.connect('mssql://testuser:testuser@192.168.1.70\\SQLEXPRESS/MyTestDB');

My details are:我的详细信息是:

  • SQL Server instance: 192.168.1.70\SQLEXPRESS SQL 服务器实例: 192.168.1.70\SQLEXPRESS
  • DB name: MyTestDB数据库名称:MyTestDB
  • uid/pwd: testuser, testuser uid/密码:testuser,testuser

I have no issues connecting from SQL Server Management Studio from a remote machine, so what is the problem in this code?我从远程计算机从 SQL Server Management Studio 连接没有问题,那么这段代码有什么问题?

json object works, not plain string ! json object 有效,不是纯字符串!

    let config = {
        user: 'testuser',
        password: 'testuser',
        server: '192.168.1.70\\SQLEXPRESS',  
        database: 'MyTestDB'
    }

Update: From a github issue it became clearer the Quick Example format is a Uri, not a connection string.更新:从 github 问题中可以清楚地看出,快速示例格式是 Uri,而不是连接字符串。

So instead of:所以而不是:

'mssql://testuser:testuser@192.168.1.70\\SQLEXPRESS/MyTestDB'

I should use the below, which I've since confirmed also works!我应该使用下面的,我已经确认它也有效!

'mssql://testuser:testuser@192.168.1.70/SQLEXPRESS/MyTestDB'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM