Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: problem with database connection  (Read 6935 times)

davidovv

  • Newbie
  • *
  • Posts: 11
    • View Profile
problem with database connection
« on: February 09, 2017, 03:41:23 pm »
I have a strange problem with limereport. Sometimes the executed report shows errors on all fields, like field not found. When i restart application the report executes ok. Report uses the same database connection parameters as my application (database is mysql). With application not able to generate report, and showing those errors, and while application is still running, i edited lrxml file, and used another username/password for database connection and retried executing the report. the report executed ok. Then again without exiting my application i reverted to previous username/password and report executed ok. My username/password has no connection limits but i still believe there is multiple connections problem.
Anyway i don't like the way limereport stores database username/password in the lrxml file and i would like to use existing database connection that is already open in my application. I think that if i could pass my connection to limereport i would solve both issues, although that connection problem must not be ignored and forgotten. Is there a way to use existing db connection? if not consider this as a feature request?

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: problem with database connection
« Reply #1 on: February 10, 2017, 04:39:36 pm »
Thanks for your message. I'll check it. Which version limereport do you use ?
Quote
Anyway i don't like the way limereport stores database username/password in the lrxml file and i would like to use existing database connection that is already open in my application
If your application has a default sql connection you can use it in the limereport. When you add a new datasource you can select "qt_sql_default_connection" as the value for the property "Connection" of this datasource. Also you can use variables in the conection settings if you do not want to limereport store the data in the report

davidovv

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: problem with database connection
« Reply #2 on: February 10, 2017, 07:39:50 pm »
I am using latest tag (1.3.12) from git, and it was built with qt 5.7.1 mingw32
The thing is that i can't find a way to reproduce the problem, as it happens quite randomly, after a lot of reports that executed without any problem. But when it starts, no report can be generated until i restart application or edit lrxml like i explained.
I would like to have username/password saved in lrxml, so that i can use some test/test username password in development and i dont have to change lrxml every time i have to deploy new version. But when the report is executed in production, i would like to use the existing connection overriding the connection set in report.
When you say
Quote
add a new datasource you can select "qt_sql_default_connection as the value for the property "Connection"
in lrdesigner there is only field "Connection Name" and it is lineedit (not select)
I was hoping for some function in my code after i create LimeReport::ReportEngine object, but i cant find it.

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: problem with database connection
« Reply #3 on: February 10, 2017, 09:07:03 pm »
I mean property "Connection" in DataSource object. 

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: problem with database connection
« Reply #4 on: February 11, 2017, 01:14:06 am »
Quote
I have a strange problem with limereport. Sometimes the executed report shows errors on all fields, like field not found.
I think I found the reason why it happens. Сonnection timeout drops the limereports connection after that limereport doesn't restore the connection because db.isOpen() continues return true; I've fixed it and push it on github.
Quote
i would like to use existing database connection that is already open in my application
If you need it i can add method that will replace an internal report connection to the connection created by an application.

davidovv

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: problem with database connection
« Reply #5 on: February 11, 2017, 01:33:21 am »
In LRDesigner, when i open the report, and click on the icon from image (table with green plus sign) i get Datasource dialog, and in Connection dropDownList there is no item named qt_sql_default_connection, There is only one item, the connection i created when i created the report with the name i gave it before in the field Connection Name

davidovv

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: problem with database connection
« Reply #6 on: February 11, 2017, 01:48:38 am »
Code: [Select]
If you need it i can add method that will replace an internal report connection to the connection created by an application.Yes it would be great, i was even thinking if default behavior should be that report uses that default application connection, unless user/programmer creates another connection, or asks the engine to use connection from report (that is kind of unsafe to store connection parameters in report).

 

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: problem with database connection
« Reply #7 on: February 11, 2017, 04:34:55 am »
LRDesigner realy doesn't have the default conection :)
We usually run the report designer directly from the app in which it embedded.
Quote
(that is kind of unsafe to store connection parameters in report)
LimeReport save pasword as crypted value and I can encrypt all the connection fields :)
Also you can use variables in the connections fields. 
But I'll think about your suggestion

« Last Edit: February 11, 2017, 04:40:28 am by Arin Alex »

davidovv

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: problem with database connection
« Reply #8 on: February 12, 2017, 02:29:20 am »
Quote
LimeReport save pasword as crypted
I checked your code, and since it is "open source" password is really unsafe, because everything needed to decrypt the password is right there in the code.
Send me any of your lrxml files and i will read database credentials within minutes.
You added the possibility to send those credentals as variables, but that complicates a little development, and it is like workaround solution.
It didn't come to my mind that limereport library has integrated designer, i allways assumed that designer is separate application. Anyway i executed lrdesigner from application and there is "qt_sql_default_connection" item in select list.
That is realy strange that standalone lrdesigner is not able to create report for any application. there is some hidden design flaw. Something is not where it should be or something is not named right.
I think that the connection should not be part of report but part of application that runs the report. Standalone LRDesigner should manage its own db connections by name
Qt has a way of creating multiple connections by name
Code: [Select]
QSqlDatabase::database() is actually default connection named "defaultConnection". The full function is
Code: [Select]
QSqlDatabase::database(const QString &connectionName = QLatin1String( defaultConnection ), bool open = true) you should use the same logic, and the same mechanism. That item in the list should be called "defaultConnection" instead of "qt_sql_default_connection", and standalone lrdesigner should be able to create one defaultConnection, and manage/save connection  parameters outside report, maybe in some settings file (even if it is unsafe), or popup ask user dynamicly when needed. So that i you can use lrdesigner for any application you have.
When executing the report, the engine should search for connection by name defined when report was designed.
Code: [Select]
QSqlDatabase::contains(const QString &connectionName = QLatin1String( defaultConnection )) can check for connection, if found it can be used.

Report is part of source code, and database passwords do not belong there
Anyway i am looking forward for your solution for managing report connection.


Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: problem with database connection
« Reply #9 on: February 13, 2017, 12:13:48 pm »
It looks like good idea :) i'll take it. Thanks.

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: problem with database connection
« Reply #10 on: March 01, 2017, 04:56:50 am »
I have made new release 1.4.1.
Whats new:
"defaultConnection" has been added to LRDesigner;
LimeReport can store connection credentials in a separate file;
LimeReport can use a connection which was established by an application by name;
You can change passphrase that is used for crypting db credentials via ReportEngine::setPassPharse(QString& passPharse) method;
IDbCredentialsProvider interface has been added
class IDbCredentialsProvider{
public:
    virtual QString getUserName(const QString& connectionName) = 0;
    virtual QString getPassword(const QString& connectionName) = 0;
};
registerDbCredentialsProvider(IDbCredentialsProvider *provider) method has been added to IDataSourceManager