【问题标题】:Connecting with SQL database using cypress使用 cypress 连接 SQL 数据库
【发布时间】:2019-11-18 12:38:01
【问题描述】:

我想知道是否有人可以帮助我解决这个问题。我正在尝试使用 cypress 连接到 SQL 数据库,但它一直显示错误消息。我正在使用以下内容:

赛普拉斯 3.6.1

NodeJs 12.13.0

npm 6.12.0

Package.json 有以下依赖:

 "devDependencies": {
 "cypress": "^3.6.0",
 "cypress-sql-server": "^1.0.0"
  },
 "dependencies": {
 "tedious": "^6.6.2"
  }

Cypress.json 具有以下格式的数据库凭据:

"env": {
"db": { 
"username": "", "password": "", "server": "localhost",
"options": { "database": "", "encrypt": true, "rowCollectionOnRequestCompletion": true } 
 }
}

在 cypress\plugins\index.js 文件中初始化插件:

const sqlServer = require('cypress-sql-server');    
module.exports = (on, config) => {
tasks = sqlServer.loadDBPlugin(config.env.db);
on('task', tasks); 
}

cypress\support\index.js 文件中导入的命令:

import sqlServer from 'cypress-sql-server';
sqlServer.loadDBCommands();

规范文件有以下测试:

cy.sqlServer('SELECT * FROM test');

赛普拉斯显示以下错误:

CypressError: cy.task('sqlServer:execute') failed with the following error:

> ConnectionError: Failed to connect to localhost\MSSQLSERVER:1433 - getaddrinfo ENOTFOUND 
localhost\MSSQLSERVER
at ConnectionError (C:\CypressTest\node_modules\cypress-sql- 
server\node_modules\tedious\lib\errors.js:13:12)
at Connection.socketError (C:\CypressTest\node_modules\cypress-sql- 
server\node_modules\tedious\lib\connection.js:1008:28)
at C:\CypressTest\node_modules\cypress-sql-server\node_modules\tedious\lib\connection.js:874:21
at GetAddrInfoReqWrap.callback (C:\CypressTest\node_modules\cypress-sql- 
server\node_modules\tedious\lib\connector.js:48:16)
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (dns.js:70:17)

【问题讨论】:

  • 确保你的 sql server 正在监听localhost:1433

标签: javascript cypress sqlconnection


【解决方案1】:

尝试将“localhost\MSSQLSERVER”解析为 IPv4 或 IPv6 地址失败。

打开 SQL Server Management Studio,窗口标题会告诉您确切的机器名称。假设它是“DEV123”,然后在您的服务器设置中,而不是:

"server":"localhost"

使用:

"server":"localhost\\DEV123"

【讨论】:

    猜你喜欢
    • 2019-12-17
    • 1970-01-01
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 2015-11-04
    • 1970-01-01
    • 2019-09-16
    相关资源
    最近更新 更多