[英]TypeORM connection issue with SQL Server
I have SQL Server instance running on my local machine, when I am trying to connect a database from TypeORM it is throwing below error:我在本地机器上运行 SQL 服务器实例,当我尝试从 TypeORM 连接数据库时,它抛出以下错误:
originalError: ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence) originalError: ConnectionError: 无法连接到 localhost:1433 - 无法连接(序列)
Here is my ormconfig.ts
file looks like:这是我的ormconfig.ts
文件的样子:
{
"type": "mssql",
"host": "localhost",
"username": "",
"password": "",
"database": "demoDB",
"synchronize": true,
"logging": true,
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
}
and here is my package.json
file:这是我的package.json
文件:
{
"name": "PLHApi-Dev",
"version": "0.0.1",
"description": "Performance Lighthouse Reborn.",
"devDependencies": {
"@types/bcryptjs": "^2.4.2",
"@types/cookie-parser": "^1.4.2",
"@types/express": "^4.17.9",
"@types/graphql": "^14.5.0",
"@types/jsonwebtoken": "^8.5.0",
"@types/node": "^8.0.29",
"nodemon": "^2.0.6",
"ts-node": "3.3.0",
"typescript": "3.3.3333"
},
"dependencies": {
"apollo-server-express": "^2.19.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.1",
"cookie-parser": "^1.4.5",
"dotenv": "^8.2.0",
"express": "^4.15.4",
"jsonwebtoken": "^8.5.1",
"mssql": "^4.3.9",
"reflect-metadata": "^0.1.10",
"type-graphql": "^1.1.1",
"typeorm": "0.2.29"
},
"scripts": {
"dev": "nodemon --exec ts-node src/index.ts"
}
}
when I am trying to run it is throwing an ESOCKET error,当我尝试运行它时会抛出 ESOCKET 错误,
originalError: ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at ConnectionError (E:\PLH_API\PLHApi-Dev\node_modules\tedious\lib\errors.js:12:12)
at Connection.socketError (E:\PLH_API\PLHApi-Dev\node_modules\tedious\lib\connection.js:1024:30)
at E:\PLH_API\PLHApi-Dev\node_modules\tedious\lib\connection.js:868:25
at SequentialConnectionStrategy.connect (E:\PLH_API\PLHApi-Dev\node_modules\tedious\lib\connector.js:154:9)
at Socket.onError (E:\PLH_API\PLHApi-Dev\node_modules\tedious\lib\connector.js:170:16)
at Socket.emit (events.js:315:20)
at Socket.EventEmitter.emit (domain.js:482:12)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'ESOCKET'
I am also attaching the SSMS configuration window screenshot,我还附上了 SSMS 配置 window 截图,
Please help me to resolve the issue.请帮我解决问题。
Thanks in advance.提前致谢。
Verifique o nome da instancia do seu SQL Server, Exemplo: LOCALHOST\MSSQLSERVER. Verifique o nome da instancia do seu SQL 服务器,示例:LOCALHOST\MSSQLSERVER。
Veja na documentação oficial do TypeORM官方文档做 TypeORM
https://typeorm.io/#/connection-options/mssql-connection-options https://typeorm.io/#/connection-options/mssql-connection-options
options.instanceName - The instance name to connect to. options.instanceName - 要连接的实例名称。 The SQL Server Browser service must be running on the database server, and UDP port 1434 on the database server must be reachable.数据库服务器上必须运行SQL服务器浏览器服务,并且数据库服务器上的UDP端口1434必须可达。 Mutually exclusive with port.与端口互斥。 (no default). (无默认值)。
No seu arquivo ormconfig.json você coloca:没有 seu arquivo ormconfig.json você coloca:
"host": "LOCALHOST",
"options": {
"instanceName": "SQLSERVER"
},
you should type port:'', below the host with the port number in the '' and the username of the SQL server you want to connect to in the '' username:'', and the password of the SQL server user login in the password:'',你应该输入端口:'',在''中的端口号和你要连接的SQL服务器的用户名的主机下面''用户名:'',以及SQL服务器用户登录的密码密码:'',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.