Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delphi and sql server questions

Status
Not open for further replies.

rutledj

Programmer
Jan 24, 2004
1
US
I'm somewhat of a novice with using these two products together but know them ok individually.

Could someone point me to some examples of how to use delphi to do a transaction in a sql server table with row locking?

I'm not sure what is the best component to use for making the db connections (connection strings?) or how to actually do a transaction in code that locks just a row vs the complete table.

Thanks,
Rut
 
Use dbExpress components SQLConnection and SQLDataset or ADO components ADOConnection and ADODataset.

Either connection component will:
1. Handle the connection to the database (surprise surprise!)
2. Handle the transaction (see ADOConection.BeginTrans, CommitTrans and RollbackTrans. Similar method names in SQLConnection)
3. Execute your SQL statements (Execute method).

If you want to retrieve data (SELECT statement), use corresponding Dataset component (linked to the connection). You can execute statements using the datasets too.

Row and Table locking. I thought SQL Server row locked by default. What happens will be determined by SQL Server settings anyway, not the Delphi call.

Sample code for implementing transactions:

with TADOConnection do
begin
BeginTrans;
try
Execute('INSERT INTO ...... (....) VALUES (........)');
Execute('UPDATE ...... SET ..... WHERE .......);

CommitTrans;
except
RollbackTrans;
end;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top