[英]TypeORM connection issue with SQL Server
我在本地機器上運行 SQL 服務器實例,當我嘗試從 TypeORM 連接數據庫時,它拋出以下錯誤:
originalError: ConnectionError: 無法連接到 localhost:1433 - 無法連接(序列)
這是我的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"
}
}
這是我的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"
}
}
當我嘗試運行它時會拋出 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'
我還附上了 SSMS 配置 window 截圖,
請幫我解決問題。
提前致謝。
Verifique o nome da instancia do seu SQL 服務器,示例:LOCALHOST\MSSQLSERVER。
官方文檔做 TypeORM
https://typeorm.io/#/connection-options/mssql-connection-options
options.instanceName - 要連接的實例名稱。 數據庫服務器上必須運行SQL服務器瀏覽器服務,並且數據庫服務器上的UDP端口1434必須可達。 與端口互斥。 (無默認值)。
沒有 seu arquivo ormconfig.json você coloca:
"host": "LOCALHOST",
"options": {
"instanceName": "SQLSERVER"
},
你應該輸入端口:'',在''中的端口號和你要連接的SQL服務器的用戶名的主機下面''用戶名:'',以及SQL服務器用戶登錄的密碼密碼:'',
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.