Bonjour !
J’utilise AdonisJS et MSSQL. J’ai quelques base de données sur le même serveur, les voici :
Voici la configuration de la db dans mon .env :
DB_CONNECTION=mssql
DB_HOST=127.0.0.1
DB_PORT=1433
DB_USER=sa
DB_PASSWORD=123456
DB_DATABASE=WEB_PANEL
Le problème est que, j’ai ma propre API pour faire les requêtes que je veux comme cela :
connectToDatabase('mssql://id:pw@localhost').then(async () => {
let onlinePlayers = await User.getOnlinePlayers()
let numberOfStaff = staff.length
let numberOfOnlinePlayers = onlinePlayers.recordset.length
return view.render('system.index', { totalPlayers: numberOfOnlinePlayers, numberOfStaff: numberOfStaff })
})
}
Mais si je fais ça, j’ai cette erreur :
warning:
warning:
WARNING: Adonis has detected an unhandled promise rejection, which may
cause undesired behavior in production.
To stop this warning, use catch() on promises or wrap await
calls inside try/catch.
TypeError: Cannot read property 'substr' of null
at parseConnectionURI (C:\Users\didi\Desktop\drpanel\panel\node_modules\mssql\lib\connectionstring.js:21:32)
at Object.resolveConnectionString [as resolve] (C:\Users\didi\Desktop\drpanel\panel\node_modules\mssql\lib\connectionstring.js:205:72)
at new ConnectionPool (C:\Users\didi\Desktop\drpanel\panel\node_modules\mssql\lib\base.js:127:40)
at new ConnectionPool (C:\Users\didi\Desktop\drpanel\panel\node_modules\mssql\lib\tedious.js:175:1)
at Object.connect (C:\Users\didi\Desktop\drpanel\panel\node_modules\mssql\lib\base.js:1592:22)
at connectToDatabase (C:\Users\didi\Desktop\drpanel\panel\drapi\src\core\connection.handler.js:4:15)
at SystemController.showSystemPage (C:\Users\didi\Desktop\drpanel\panel\app\Controllers\Http\Panel\SystemController.js:8:9)
at Server._routeHandler (C:\Users\didi\Desktop\drpanel\panel\node_modules\@adonisjs\framework\src\Server\index.js:121:31)
at MiddlewareBase._resolveMiddleware (C:\Users\didi\Desktop\drpanel\panel\node_modules\@adonisjs\middleware-base\index.js:195:28)
at Runnable._invoke (C:\Users\didi\Desktop\drpanel\panel\node_modules\co-compose\src\Runnable.js:76:42)
at C:\Users\didi\Desktop\drpanel\panel\node_modules\co-compose\src\Runnable.js:73:34
at f (C:\Users\didi\Desktop\drpanel\panel\node_modules\once\once.js:25:25)
at Authenticated.handle (C:\Users\didi\Desktop\drpanel\panel\app\Middleware\Authenticated.js:16:19)
at async ConvertEmptyStringsToNull.handle (C:\Users\didi\Desktop\drpanel\panel\app\Middleware\ConvertEmptyStringsToNull.js:13:5)
at async AuthInit.handle (C:\Users\didi\Desktop\drpanel\panel\node_modules\@adonisjs\auth\src\Middleware\AuthInit.js:60:5)
at async Shield.handle (C:\Users\didi\Desktop\drpanel\panel\node_modules\@adonisjs\shield\src\Shield\index.js:417:5)
Pour getOnlinePlayers, le code est le suivant :
static async getOnlinePlayers() {
let onlinePlayers = await sql.query`
USE DR2_USER
SELECT TOP 10 * FROM TB_CharacterSub
WHERE f_ConnectionChannel != 0`
return onlinePlayers
}
En l’occurrence ici j’aimerais utiliser la base de donnée DR2_USER
mais je ne peux pas :/
Quelqu’un aurait une solution svp ?
Merci !
+0
-0