Open Shankar-CodeJunkie opened 1 month ago
I'm not a DB2 expert but judging by the error message, it seems like you don't have the table name "username.WiusrappPersonV1". Perhaps the schema name of that table is WIUSRAPP
? You might want to specify it in the datasource.
Thanks @dhmlau
As mentioned on the issue #2504, I use dsn property to provide the DB2 server details, where I do mention the schema name ..
Yes correct the schema name of the table is WIUSRAPP
. I have it specified on the datasource
My datasource is as below
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';
const config = {
name: 'IbmBludbDataSourcev1',
connector: 'db2',
schema: 'WIUSRAPP',
dsn: 'DATABASE=Bludb;HOSTNAME=xxxx;PORT=50001;PROTOCOL=TCPIP;UID=xxx;PWD=xxx;Security=SSL;schema:WIUSRAPP'
};
// Observe application's life cycle to disconnect the datasource when
// application is stopped. This allows the application to be shut down
// gracefully. The `stop()` method is inherited from `juggler.DataSource`.
// Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html
@lifeCycleObserver('datasource')
export class IbmBludbDataSourcev1DataSource extends juggler.DataSource
implements LifeCycleObserver {
static dataSourceName = 'IbmBludbDataSourcev1';
static readonly defaultConfig = config;
constructor(
@inject('datasources.config.IbmBludbDataSourcev1', {optional: true})
dsConfig: object = config,
) {
super(dsConfig);
}
}
In the dsn
string, would it be schema=WIUSRAPP
(consistent with the rest of the string) instead of using :
?
@dhmlau :
Yes, that was a typo, but even changing it to schema=WIUSRAPP
gives the same error message. Now I see the tablename appearing on the error message.
[Error: [IBM][CLI Driver][DB2/LINUXX8664] SQL0204N "KIPRAKA1_IN_IBM_COM.TESTSHANKAR" is an undefined name. SQLSTATE=42704
] {
error: '[ibm_db] SQL_ERROR',
sqlcode: -204,
state: '42S02'
}
I have also shown a screenshot of DBeaver image, where you can see the table exist on the database
Why UID name is getting appended on the query instead of schema name ?
Is this something similar to the issue documented on #145
@dhmlau:
After researching, I found out that I was referring the schema name incorrectly on the dsn string. It seems, in the dsn string on the datasource.ts, we need to mention the schema name against CurrentSchema
instead of Schema
The correct property name in the DSN string is CurrentSchema
and I was wrongly referencing it as schema
earlier, because of which it was connecting to an incorrect schema and unable to get to the table.
dsn:'DATABASE=dbname;HOSTNAME=hostname;PORT=50001;PROTOCOL=TCPIP;UID=username;PWD=pwd;Security=SSL;CurrentSchema=schemaname'
It would be better, if we have this updated on the documentation. I will open up a new Pull request for the documentation update. Thank you
You can close the issue. Thanks for your help
My dependencies
Steps to reproduce
lb4 app
lb4 datasource <>. ---- Choose IBM Db2 (for Linux, Unix, Windows) (supported by StrongLoop) and also use dsn instead of individual values
lb4 repository
lb4 controller
Current Behavior
When you run
npm start
, the application starts, when you hit any of the endpoint, where you have the logic to have database interactions, it errors out even on create / count methods. Any interaction is failing.await this.wiusrappPersonV1Repository.create({"PROFILE_ID": "abc123"})
I see an error on my console saying
await this.wiusrappPersonV1Repository.create({"PROFILE_ID": "abc123"}) .then(x => console.log('hey', x)) .catch(err => console.log('err', err))
However, I can confirm that the db2 system has the table
TESTSHANKAR
, which is configured or mapped on the modelExpected Behavior
The DB2 connection isn't getting established.
Additional information
I did check some existing issues for the error message, and followed the solution but not working
https://github.com/loopbackio/loopback-next/issues/2504
Related Issues
I did find this issue matching to my problem, and I used that solution but still getting the same problem
https://github.com/loopbackio/loopback-next/issues/2504