TypeOrm - Nest.js 无法连接到 XX:1433 - 自签名证书

Cri*_*era 4 typeorm nestjs

当尝试连接到 SQL Server 时,出现以下错误:

[Nest] 96151  - 30/07/2021 18:28:34   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
ConnectionError: Failed to connect to XXXXXX:1433 - self signed certificate*
Run Code Online (Sandbox Code Playgroud)

我的 ormconfig.json:

[Nest] 96151  - 30/07/2021 18:28:34   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
ConnectionError: Failed to connect to XXXXXX:1433 - self signed certificate*
Run Code Online (Sandbox Code Playgroud)

小智 12

将此行添加到 typeorm 配置中的代码中。选项:{ 加密: false }

你的配置代码将是这样的:

type: 'mssql', host: 'localhost', port: 1433, username: 'sa', password: '@Yourpassword123', database: 'yourdatabase', autoLoadEntities: true, synchronize: true, options: { encrypt: false },

我使用“sa”作为用户,因为它是 sql server 的默认用户名。根据需要调整上面的代码配置!


Cri*_*era 7

您只需要添加 ormconfig.json 即可为我工作

“选项”:{“trustServerCertificate”:true}

{
    "type": "mssql",
    "host": "XXXXXX",
    "port": 1433,
    "username": "user",
    "password": "pass",
    "database": "BDName",
    "entities": ["dist/**/*.entity{.ts,.js}"],
    "synchronize": true,
    "options": {"trustServerCertificate": true}   
}
Run Code Online (Sandbox Code Playgroud)