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

LVL 2
FelixinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

geobul
0
FelixinAuthor Commented:
Hi,

MS SQL 6.5

is what I'm using
0
kretzschmarCommented:
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
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

FelixinAuthor Commented:
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
0
geobulCommented:
Hi,

First: it's in BDE.

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

Geo
0
FelixinAuthor Commented:
See my own answer

(I've found the solution)
0
FelixinAuthor Commented:
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.
0
ianBCommented:
Hi,

I am answering this question so it can be saved as a PAQ. I have refunded the points back to your account.

Ian
Community Support @ Experts Exchange
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.