Link to home
Start Free TrialLog in
Avatar of Vendi
Vendi

asked on

Table.Post question

I need an explanation for the following.
I was using this code to insert into a table:

Table.Close;
Table.Open;
Table.Insert;
Table.FieldByName('One').AsInteger = X;
.
etc.
Table.Post;
.
same code repeated for second table
.

This is a simplified example but still gives the general idea.  The application using this code worked for several months.  Then started hanging on the Table.Post line of first table.  Sometimes, the data would post and sometimes in would not (usually not).  It always caused the application to stop responding and usually the machine had to be restarted.

The problem was solved using:
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add(SomeSQLStatement);
Query1.ExecSQL;

Of the two tables, the first had about 167 records and the second, 2000. What caused this?  Has anyone else ran into the same problem?  The points will go to the person who tells me what caused the problem (and provides enough details to support their answer).

Using Delphi 5 Enterprise, Windows 98 machines, SQL Server 6.5, NT server.
Avatar of Asw
Asw

Hi Vendi,

I had some sort of problem like this  a while ago try.


Table.Close;
Table.Open;
Table.Insert;
TableOne.Value := X;
..
etc.
Table.Post;

Asw
what database are you using...

have you switched delphi versions at some point in the program's lifetime

have you upgraded the bde at all at some point

I don't have a suggestion as to why the table.post line hangs, but shouldn't this line:

Query1.ExecSQL;

be

Query1.Open;

?

Cheers,

Raymond.
I met such problems when using mssql.
I find that, if some triggers or identify fields is in the table, the problems may .
try to delete all triggers and do not use identify fields, or, use tquery instead.
Avatar of Vendi

ASKER

rwilson, i believe Query1.Open is used when using a select or similiar statement (returning result sets).  However, ExecSQL works for update, insert, delete, etc. - no result set.
..
Phoenix_s, your comments are very interesting, in fact, we did switch from Delphi 4 standard to Delphi 5 enterprise during the development of this program.  (using MS SQL server 6.5)Do you have any more information on why or if it caused this problem?
Avatar of Vendi

ASKER

chengjian, thanks for your proposed answer, but there are no triggers being used in this application.  Also, what exactly do you mean by identify field?  Unless you know WHY this problem is occurring, please don't answer it.  I specifically stated that the points would go to the person who could explain the cause of this problem.
ASKER CERTIFIED SOLUTION
Avatar of TAZI
TAZI
Flag of South Africa image

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
Avatar of Vendi

ASKER

Adjusted points to 40
Avatar of Vendi

ASKER

Phoenix s,  do you have anymore information on that?
I am currently developing with SQL server 6.5 and delphi 4 (w/ SP2)

I ran into problems posting data into a table that had an 'identity' column... then it'd lose track of which record the cursor was sitting on.

so... needless to say... I had to kill the identity column.. and insert a standard int field and create a stored proc to generate unique key fields (actually this is the way I generate all unique record identifiers)

this issue of mine also had something to do with master-detail issues as well.

are the 2 tables you're referring to part of a master detail set, or are they 2 distinct and seperate entities?  If so... you have to post to the master table first, then the detail, especially if you have any referential integrity constraints to deal with.

anyway... a little more background as to exactly what you are trying to accomplish here might be in order for me to be of further use to you...

cheers!
Avatar of Vendi

ASKER

no, I'm not using master-detail.  These two tables are updated with new information from user input.  the unique key fields of these tables are not automatically generated.  an existing key exists for each individual and we use this same unique number.  there are no referential integrity issues to cause this problem.  
Avatar of Vendi

ASKER

Thanks for your comments TAZI, Phoenix I am also putting out some points for you in another question.  I appreciate all your comments so far and look forward to reading any more.