Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Where to put dbxConnections.ini for deployed application?


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Feb 23, 2016 12:38 PM Last Post By: Antonio Estevez Threads: [ Previous | Next ]
Mats karlsson

Posts: 64
Registered: 11/8/99
Where to put dbxConnections.ini for deployed application?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 16, 2016 10:15 AM
Hello,
Is there a 'standard' location for putting the dbxConnections.ini file, if any, for a deployed dbExpress application?

I am deploying a local sqlite database and have problems with the logic of how dbExpress loads connections. Everything is fine while debugging in the IDE, but what about for a deployed application?

And the LoadParamsOnConnect, should it not be LoadParamsOnBeforeConnect ?

In addition, the help file have this language: "In most cases, it is unnecessary to load connection configurations at runtime because when you set ConnectionName at design time, the DriverName and Params properties are automatically set as well."

I don't see how that will work in a deployed scenario where the database location WILL differ from a developers sandbox.

So since the DB itself will reside in the users local appdata folder, I assume I have to create a 'custom' dbxConnection.ini file with modified records inside to properly indicate the exact location of the deployed database?

Or is there a better way?

tk
Mats karlsson

Posts: 64
Registered: 11/8/99
Re: Where to put dbxConnections.ini for deployed application?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 18, 2016 2:18 PM   in response to: Mats karlsson in response to: Mats karlsson
totte karlsson wrote:
Hello,
Is there a 'standard' location for putting the dbxConnections.ini file, if any, for a deployed dbExpress application?

I am deploying a local sqlite database and have problems with the logic of how dbExpress loads connections. Everything is fine while debugging in the IDE, but what about for a deployed application?

I'm finding out that the deployment of a dbExpress application is kind of tricky. There seem not to be any way that my application is NOT trying to load the database info on startup, trying some invisible, to me, algorithm. If it is on a machine where the driver and db info is not in the 'Codegear registry' it will just fail. And I don't see how to recover from the exceptions that are thrown from the dbconnections constructors(?)

However, it seems that if you deploy the dbxdrivers.ini and dbxconnectionx.ini with the application, it can work (if codegear ide is not installed). For now I'm putting these files in the Program files folder together with the application.

However, if the application is installed on a machine that are also having CG IDE installed, the application again will fail because it will go and read in the CG registry, and may not find the right driver there. And again the application will crash. Is this behavior by design?
Or am I missing something obvious?

Edited by: totte karlsson on Feb 19, 2016 9:36 AM
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Where to put dbxConnections.ini for deployed application?
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 19, 2016 1:34 PM   in response to: Mats karlsson in response to: Mats karlsson
El 19/02/2016 a las 18:37, totte karlsson escribió:
totte karlsson wrote:
Hello,
Is there a 'standard' location for putting the dbxConnections.ini file, if any, for a deployed dbExpress application?

I am deploying a local sqlite database and have problems with the logic of how dbExpress loads connections. Everything is fine while debugging in the IDE, but what about for a deployed application?

I'm finding out that the deployment of a dbExpress application is kind of tricky. There seem not to be any way that my application is NOT trying to load the database info on startup, trying some invisible, to me, algorithm. If it is on a machine where the driver and db info is not in the 'Codegear registry' it will just fail. And I don't see how to recover from the exceptions that are thrown from the dbconnections constructors(?)

However, it seems that if you deploy the dbxdrivers.ini and dbxconnectionx.ini with the application, it can work (if codegear ide is not installed). For now I'm putting these files in the Program files folder together with the application.

However, if the application is installed on a machine that are also having CG IDE installed, the application again will fail because it will go and read in the CG registry, and may not find the right driver there. And again the application will crash. Is this behavior by design?
Or am I missing something obvious?

Edited by: totte karlsson on Feb 19, 2016 9:36 AM

You don't need to deploy the .ini files:

Try this:
Set Connected to false
Set LoadParamsOnConnect to false

Add a Connect function to the public section of your datamodule
__published:	// IDE-managed Components
...
    TSQLConnection *SQLConnection1;
...
public:		// User declarations
    __fastcall TDataModule1(TComponent* Owner);
...
    bool _fastcall Connect(String DatabaseFile);
...
};


And the function implementation to the .cpp:
bool _fastcall TDataModule1::Connect(String DatabaseFile)
{
    try
    {
       SQLConnection1->Connected= false;
       SQLConnection1->Params->Values[_D("Database")]= DatabaseFile;
       SQLConnection1->Connected= true;
    }
    catch (const Exception &E)
    {
       Application->MessageBox(
          E.Message.c_str(),
          _D("Error connecting to database"),
          MB_ICONSTOP | MB_OK);
    }
    return SQLConnection1->Connected;
}

Connect to the database when you need, by example, in the OnShow Event of your main form:

void __fastcall TForm1::FormShow(TObject *Sender)
{
    String DatabaseFile= _D("FullPathToTheSqliteDatabaseFile");
 
    if (DataModule1->Connect(DatabaseFile))
    {
       // Connection successfull
    }
    else
    {
       // Connection failed
    }
}
Mats karlsson

Posts: 64
Registered: 11/8/99
Re: Where to put dbxConnections.ini for deployed application?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2016 12:22 PM   in response to: Antonio Estevez in response to: Antonio Estevez
Thanks Antonio,
I hope that will work.
However, before trying: where does the connection get driver information from using your approach?

Antonio Estevez wrote:
El 19/02/2016 a las 18:37, totte karlsson escribió:
totte karlsson wrote:
Hello,
Is there a 'standard' location for putting the dbxConnections.ini file, if any, for a deployed dbExpress application?

I am deploying a local sqlite database and have problems with the logic of how dbExpress loads connections. Everything is fine while debugging in the IDE, but what about for a deployed application?

I'm finding out that the deployment of a dbExpress application is kind of tricky. There seem not to be any way that my application is NOT trying to load the database info on startup, trying some invisible, to me, algorithm. If it is on a machine where the driver and db info is not in the 'Codegear registry' it will just fail. And I don't see how to recover from the exceptions that are thrown from the dbconnections constructors(?)

However, it seems that if you deploy the dbxdrivers.ini and dbxconnectionx.ini with the application, it can work (if codegear ide is not installed). For now I'm putting these files in the Program files folder together with the application.

However, if the application is installed on a machine that are also having CG IDE installed, the application again will fail because it will go and read in the CG registry, and may not find the right driver there. And again the application will crash. Is this behavior by design?
Or am I missing something obvious?

Edited by: totte karlsson on Feb 19, 2016 9:36 AM

You don't need to deploy the .ini files:

Try this:
Set Connected to false
Set LoadParamsOnConnect to false

Add a Connect function to the public section of your datamodule
__published:	// IDE-managed Components
...
    TSQLConnection *SQLConnection1;
...
public:		// User declarations
    __fastcall TDataModule1(TComponent* Owner);
...
    bool _fastcall Connect(String DatabaseFile);
...
};


And the function implementation to the .cpp:
bool _fastcall TDataModule1::Connect(String DatabaseFile)
{
    try
    {
       SQLConnection1->Connected= false;
       SQLConnection1->Params->Values[_D("Database")]= DatabaseFile;
       SQLConnection1->Connected= true;
    }
    catch (const Exception &E)
    {
       Application->MessageBox(
          E.Message.c_str(),
          _D("Error connecting to database"),
          MB_ICONSTOP | MB_OK);
    }
    return SQLConnection1->Connected;
}

Connect to the database when you need, by example, in the OnShow Event of your main form:

void __fastcall TForm1::FormShow(TObject *Sender)
{
    String DatabaseFile= _D("FullPathToTheSqliteDatabaseFile");
 
    if (DataModule1->Connect(DatabaseFile))
    {
       // Connection successfull
    }
    else
    {
       // Connection failed
    }
}
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Where to put dbxConnections.ini for deployed application?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2016 12:38 PM   in response to: Mats karlsson in response to: Mats karlsson
El 23/02/2016 a las 21:22, totte karlsson escribió:
Thanks Antonio,
I hope that will work.
However, before trying: where does the connection get driver information from using your approach?

I suppose you have already selected the connection information in the property editor

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02