Link to home
Start Free TrialLog in
Avatar of Felixin
Felixin

asked on

Iterating through datamodule components fails with persistent fields

Hi,

I have a piece of code on a OnCreate event of a datamodule which looks as follows:

----------------------
  try
    if not SS.Active then
      SS.Active := TRUE;

    DB.Connected    := FALSE;
    DB.SessionName  := SS.SessionName;
    DB.DatabaseName := 'DB' + SS.SessionName;
    DB.Connected    := TRUE;


    for I := 0 to (ComponentCount - 1) do
    begin
      if (Components [I] is TTable) then
      try
        TTable (Components [I]).Active       := FALSE;
        TTable (Components [I]).SessionName  := SS.SessionName;
        TTable (Components [I]).DataBaseName := DB.DatabaseName;
        TTable (Components [I]).Active       := TRUE;
      except
        ...
        raise;
      end;
      if (Components [I] is TQuery) then
      try
        TQuery (Components [I]).Close;
        TQuery (Components [I]).SessionName  := SS.SessionName;
        TQuery (Components [I]).DataBaseName := DB.DatabaseName;
      except
        ...
        raise;
      end;
    end;

    QEmpSel.Active  := TRUE;
    QEmpresa.Active := TRUE;

  except
    ShowMessage ('ERROR');
    Application.Terminate;
  end;
-------------------
(Hope you can see it OK)

What is makes is to assign the session and database names to all the tables and queries in the data module.

Well, it works ONLY IF THERE IS NO PERSISTENT FIELDS IN THE TABLES.

I mean, if I click twice on a table and add all fields (or even only one) onto the fields editor, it stops working.

WHY?
HOW TO CORRECT THIS BEHAVIOUR?

Thanks

Avatar of geobul
geobul

Hi Felixin,
What kind of Database you use ?
I've tried your code with some DB's and did not found any problem.

geobul
Avatar of Felixin

ASKER

Hi,

MS SQL 6.5

is what I'm using
Avatar of kretzschmar
hi felixin,

could it be that the tablestructures are different, becuase a persistent field does not have a database-property nor a session-property, therefore your changes should not affect problems with persistence-fields, except the dataset-structure is changed or the fieldname does not match.

meikl
Avatar of Felixin

ASKER

Please forget about persistent fields:

I have just discovered that it fails when 32 datasets (TTables/TQueries) are already opened.

Is there a limit, in the BDE or in the MS SQL, for the number of open objects connected to a database and to a session?

(I Know it exists for dBase and Paradox:
TI2751)

For kretzschmar :

In any case, what you are pointing might be posible, but, how could it be?:
I'm not changing the information that is set when I make an "add all fields" on the fields editor and, I swear, I'm not changing the table structure at run time.

Thanks
Hi,

First: it's in BDE.

Use BDE Administrator utility to increase MAXFILEHANDLES in
Configuration - System - INIT
to the apropriate value.

Geo
Avatar of Felixin

ASKER

See my own answer

(I've found the solution)
Avatar of Felixin

ASKER

ATTENTION:

Any answer received since now will be rejected.

I HAVE DISCOVERED THE ANSWER ON MY OWN:

MAX DBPROCESSES must be set to a number bigger than the number of datasets you expect to open.

I changed it from 31 to 64 and it worked.

For geobul:

Some words to you:

The MAXFILEHANDLES should be changed when you are using dBase or Paradox tables, as they are stored in files.
It is useless for SQL dtabases
(I believe).

Thanks to all of you.
ASKER CERTIFIED SOLUTION
Avatar of ianB
ianB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial