Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 14 total
Thread Change Database from the same session at runtime
Tue, Nov 8 2016 6:53 PMPermanent Link

KimHJ

Comca Systems, Inc

I'm using EDB and I have a session with several identical databases and one database holding one table with customer id and database name.

In my EWB project I have a Database Unit which was created using the Database Manager in the EWB IDE.

How can I change the DatabaseName in the database Connection properties or is there another way to do this?

In the IDE the Database is called MyData and the DatabaseName in the Connection Properties is FCustomer. But it could have been BCustomer or SCustomer. All Dataset's are in unit called Database1.

I tried this but it did not work. Database1.DatabaseName := BCustomer;
Get an Error Dataset load response error (Database "BCustomer" not found)

Thanks,
Kim Jensen
Wed, Nov 9 2016 1:49 AMPermanent Link

R&D team @ Environment Canada

hi Kim

I think you were on the right track.

Below is a snippet from the EWB2.05 help file, maybe you should not be saying 'database1.databaseName := ...' but rather 'database.databaseName :- ...

This is what we do on one of our projects, and it works as intended.

.. Bruno'

>>>>>>>>>>>>>> from the EWB2.05 help file <<<<<<<<<<<<<<<<<<<<<

Unit: WebData

Inherits From TObject

The TDatabase component represents a database container for all datasets in an application and provides properties and methods for loading datasets and executing transactions. An instance of the TDatabase component called Database is automatically created by the framework at application startup, so further instances of the TDatabase component should not be created.



KimHJ wrote:

I'm using EDB and I have a session with several identical databases and one database holding one table with customer id and database name.

In my EWB project I have a Database Unit which was created using the Database Manager in the EWB IDE.

How can I change the DatabaseName in the database Connection properties or is there another way to do this?

In the IDE the Database is called MyData and the DatabaseName in the Connection Properties is FCustomer. But it could have been BCustomer or SCustomer. All Dataset's are in unit called Database1.

I tried this but it did not work. Database1.DatabaseName := BCustomer;
Get an Error Dataset load response error (Database "BCustomer" not found)

Thanks,
Kim Jensen
Wed, Nov 9 2016 12:52 PMPermanent Link

KimHJ

Comca Systems, Inc

Hi Bruno,

Thanks but I still can't get it to work, I get a bug if I enter Database only because it can't find a variable called Database.DatabaseName. Maybe in your project the var is like this:

var
  Database: TDatabase1;

When I add a Database from the Database Manager EWB creates a instance of the TDatabase like this:

TDatabase1 = class(TDatabase)

and a variable called:

var
  Database1: TDatabase1;

So you should think that if I change the Database1.DatabaseName := 'MYData';

If it works in your project are you doing anything else before assigning the database name?

Thanks,
Kim


Bruno Larochelle @ Environment Canada wrote:


Below is a snippet from the EWB2.05 help file, maybe you should not be saying 'database1.databaseName := ...' but rather 'database.databaseName :- ...

This is what we do on one of our projects, and it works as intended.

.. Bruno'

>>>>>>>>>>>>>> from the EWB2.05 help file <<<<<<<<<<<<<<<<<<<<<

Unit: WebData

Inherits From TObject

The TDatabase component represents a database container for all datasets in an application and provides properties and methods for loading datasets and executing transactions. An instance of the TDatabase component called Database is automatically created by the framework at application startup, so further instances of the TDatabase component should not be created.
Wed, Nov 9 2016 1:29 PMPermanent Link

Walter Matte

Tactical Business Corporation


You can get a new database via a module (Like TDataModule in Delphi)  go to File - New  - Database

or if you declare a variable

Database123 : TDatabase;

Then you have to create and free it.

Database123 := TDatabase.Create;

and later

Database123.free;


"Database"  as you read in the help is an autocreated TDatabase - I generally just use it - I have no need to create another one.

Walter


KimHJ wrote:

Hi Bruno,

Thanks but I still can't get it to work, I get a bug if I enter Database only because it can't find a variable called Database.DatabaseName. Maybe in your project the var is like this:

var
  Database: TDatabase1;

When I add a Database from the Database Manager EWB creates a instance of the TDatabase like this:

TDatabase1 = class(TDatabase)

and a variable called:

var
  Database1: TDatabase1;

So you should think that if I change the Database1.DatabaseName := 'MYData';

If it works in your project are you doing anything else before assigning the database name?

Thanks,
Kim


Bruno Larochelle @ Environment Canada wrote:


Below is a snippet from the EWB2.05 help file, maybe you should not be saying 'database1.databaseName := ...' but rather 'database.databaseName :- ...

This is what we do on one of our projects, and it works as intended.

.. Bruno'

>>>>>>>>>>>>>> from the EWB2.05 help file <<<<<<<<<<<<<<<<<<<<<

Unit: WebData

Inherits From TObject

The TDatabase component represents a database container for all datasets in an application and provides properties and methods for loading datasets and executing transactions. An instance of the TDatabase component called Database is automatically created by the framework at application startup, so further instances of the TDatabase component should not be created.
Wed, Nov 9 2016 1:45 PMPermanent Link

Raul

Team Elevate Team Elevate

On 11/8/2016 6:53 PM, KimHJ wrote:
> I'm using EDB and I have a session with several identical databases and one database holding one table with customer id and database name.

OK - just be aware that database in EWB is NOT the same thing as
database in EDB world exactly.

EWB database is a virtual construct to allow for things like dataset
loading, transactions etc.

> In my EWB project I have a Database Unit which was created using the Database Manager in the EWB IDE.

What exactly is on here? are you referring to "datasets" you have in
this unit or did you actually instantiate new database (TDataBase) here?

> How can I change the DatabaseName in the database Connection properties or is there another way to do this?

If i understand this question then you cannot really do this from EWB.

At the end of the day EWB database simply defines the "database=" param
of the request - this database must already exist in the back-end (i.e.
in IDE you have to use database manager to create one).


> In the IDE the Database is called MyData and the DatabaseName in the Connection Properties is FCustomer. But it could have been BCustomer or SCustomer. All Dataset's are in unit called Database1.

You cannot do this with what's built into EWB - you would need to create
3 databases in the IDE database manager : MyDataF, MyDataB and MyDataS
and then i EWB code you would do "database.databasename := 'MyDataF" etc.

Other way is to create a custom module that can dynamically connect to
the correct database.

Raul
Wed, Nov 9 2016 2:56 PMPermanent Link

KimHJ

Comca Systems, Inc

>>>Kim wrote
>>> In the IDE the Database is called MyData and the DatabaseName in the Connection Properties is FCustomer. >>>But it could have been BCustomer or SCustomer. All Dataset's are in unit called Database1.

>>Raul wrote:
>>You cannot do this with what's built into EWB - you would need to create
>>3 databases in the IDE database manager : MyDataF, MyDataB and MyDataS
>>and then i EWB code you would do "database.databasename := 'MyDataF" etc.

>>Other way is to create a custom module that can dynamically connect to
>>the correct database.

Since all Dataset's are identical in Fcustomer BCustomer and in the same session I'm surprise that there is no way to change it.

My other option was to have all data in one database and use a Customer id column to only show each customer their data, is there away to apply a filter before LoadRows?

Thanks,
Kim
Wed, Nov 9 2016 4:20 PMPermanent Link

Raul

Team Elevate Team Elevate

On 11/9/2016 2:56 PM, KimHJ wrote:
> Since all Dataset's are identical in Fcustomer BCustomer and in the same session I'm surprise that there is no way to change it.

I'll see if anybody else corrects me but AFAIK this is current buil;t-in
limitation.

One reason for this was due to security - only data EWB app can access
is databases/datasets defined on server by you. This limits exposure to
dynamic sql attacks. Yours is a special case of that with dynamic
connection reconfig.

You can write a custom data module to achieve this yourself of course.

> My other option was to have all data in one database and use a Customer id column to only show each customer their data, is there away to apply a filter before LoadRows?

That's definitely an option.

Can the customers dynamically create new databases?

Otherwise the master database could hold the EWB database name (in
addition to EDB database) name and you simply update EWB app database to
use that name when user logs in.

The only downside here is that at some point somebody has to configure
the database in EWB Web Server once so it's ready.

Raul

Wed, Nov 9 2016 5:28 PMPermanent Link

KimHJ

Comca Systems, Inc

Raul wrote:

>>> My other option was to have all data in one database and use a Customer id column to only show each >>>customer their data, is there away to apply a filter before LoadRows?

>>That's definitely an option.

>>Can the customers dynamically create new databases?

No, we create the database.

>>Otherwise the master database could hold the EWB database name (in
>>addition to EDB database) name and you simply update EWB app database to
>>use that name when user logs in.


>>The only downside here is that at some point somebody has to configure
>>the database in EWB Web Server once so it's ready.

Are you talking about having all the databases installed in EWB and have a unit for each database in the project?

I was trying filter like this, but it always give me the first record even it have a different CustomerID.

       CustID: String;
       CustID := '1000';
       Database.DatabaseName:='Mydata';
       StoreTbl.Params.Clear;
       StoreTbl.Params.Add('CustomerID=''' + CustID + '''');
       LoadRows(StoreTbl);

Thanks,
Kim
Wed, Nov 9 2016 6:34 PMPermanent Link

Raul

Team Elevate Team Elevate

On 11/9/2016 5:28 PM, KimHJ wrote:
> Are you talking about having all the databases installed in EWB and have a unit for each database in the project?

Kind of.

You mentioned that all your databases are same in terms of structure and
you just need EWB to talk to the correct one based on the user (i assume
at login time you can retrieve the database that user should use).

Your TDatasets are all the same - it does not matter which database they
are connecting to so don't create duplicates.

Even though you dragged them from database manager they don't actually
get coupled to the database - database manager is a design time tool.

Dataset your dragged is not lined to that database - you specify
database using "Database.DatabaseName" in the app (you can create your
own TDatabase as well but i'll stick to built0ion default one).

For example based on your original post you might have 3 databases in
EWB IDE/Web Server : FCustomer, BCustomer and SCustomer.

Your app after logging in would simply do :

Database.DatabaseName := 'FCustomer';

You only need to this once (on app login for example) and then dataset
code would work normally  : loadrows, transactions, etc.

Super simplified example:

1. let's assume i have 2 EDB databases : DEMO and PROD and both have
same table called "datatbl" with same structure (but different data in
the table)

2.1 in EWB IDE i now create a new database called DEMO and configure
connection properties to point to DEMO EDB database
2.2 i also create a new dataset called DATA and row source is "datatbl"
table in EDB
2.3 i now repeat and create another database called PROD that points to
EDB PROD database
2.4 i also create a new dataset called DATA and row source is "datatbl"
table in EDB under PROD

3. in EDB now i drag one of those DATA datasets to my form (does not
matter which - do it either from PROD or DEMO database).


4. for simplification i'll an TEdit and Button to load the dataset based
on what the login user name is (you would look up it properly)

   if Edit1.text ='john' then
     Database.DatabaseName:='PROD'
   else
     Database.DatabaseName:='DEMO';

5. now in the app you can do something like this and it will use
whatever database you previously specified.

   database.loadrows(data);



Raul
Wed, Nov 9 2016 10:10 PMPermanent Link

KimHJ

Comca Systems, Inc

Raul wrote:

On 11/9/2016 5:28 PM, KimHJ wrote:
>>> Are you talking about having all the databases installed in EWB and have a unit for each database in the project?

>>Kind of.

Each time I need a new database I would then have to add the new database to the Database Manager and compile and deploy.

Even I don't create a TDatabase unit for each database as long as I have them in the EWB Database Manager I can access them after the project is Deployed?

Will that say that all the settings for all the Databases in the Database Manager in the EWB is deployed with every project even I if don't create a TDatabase unit?

If I could get this filter to work I think it would be a better way.

      CustID: String;
      CustID := '1000';
      Database.DatabaseName:='Mydata';
      StoreTbl.Params.Clear;
      StoreTbl.Params.Add('CustomerID=''' + CustID + '''');
      LoadRows(StoreTbl);

I get all rows what is missing?

Thanks for all you help,
Kim
Page 1 of 2Next Page »
Jump to Page:  1 2
Image