TADOConnection.Errors

TADOConnection.Errors

Post by Stefan Olo » Fri, 03 Jun 2005 16:22:40


Hi all

I have two tables populated with data. Table2 has a foreign key to Table1
and no cascading delete is set.
To avoid multiple calls over a slow network to the server I make a batch
call of commands instead of
one call for each statement.

Using CursorLocation := clUseServer I don't get the ADOConnection.Errors
populated even thou errors occur in
the batch. Using clUseClient all works well.

How do I get the ADOConnection.Errors to be populated even when using
CursorLocation := clServerSide?

Regards
Stefan Olofsson

-------------------------------
create table Table1(Id int primary key)
create table Table2(Id int primary key, Table1Id int references
able1(Id)) -- obs no cascading delete!

insert into Table1(Id) values(1)
insert into Table1(Id) values(2)
insert into Table2(Id, Table1Id) values(1, 1)

Table1
Id
1
2

Table2
Id Table1Id
1 1
-------------------------------


procedure TForm1.Button1Click(Sender: TObject);
var
Ix : integer;
Err : string;
DataConnection : TAdoConnection;
Query : TADOQuery;
begin
DataConnection := TAdoConnection.Create(nil);
DataConnection.ConnectionString := ' Connection to a MS SQL Server 2000
database ';
DataConnection.LoginPrompt := false;
DataConnection.CursorLocation := clUseServer; // set to clUseClient and
DataConnection.Errors will be populated
DataConnection.IsolationLevel := ilReadCommitted;
DataConnection.KeepConnection := true;
DataConnection.Open;

Query := TADOQuery.Create(nil);
Query.Connection := DataConnection;

DataConnection.BeginTrans;
Query.SQL.Text := 'delete from Table1 where Id = 2' + #13#10 +
'delete from Table1 where Id = 1'; // This line will
violate the foreig key constraint

Query.ExecSQL;
if DataConnection.Errors.Count = 0 then
DataConnection.CommitTrans
else begin
for Ix := 0 to DataConnection.Errors.Count - 1 do
if Err = '' then Err := DataConnection.Errors[Ix].Source + ', ' +
DataConnection.Errors[Ix].Description
else Err := Err + #13#10 + DataConnection.Errors[Ix].Source + ', ' +
DataConnection.Errors[Ix].Description;
DataConnection.RollbackTrans;
end;
DataConnection.Errors.Clear;

if Err <> '' then ShowMessage(Err);

DataConnection.Free;
Query.Free;
end;
 
 
 

1. TADOConnection within Service application

2. TADOConnection and restoring a database

Hi All,

I have an ADO Connection that I close before trying to restore using DMO.
I need to wait almost a minute before atempting the restore though,
otherwise the DMO returns an error saying that the Database is still in use.

Is there anything I can do or set on the ADO Connection to make this time
shorter.

I am connecting to a SQL Server DB and the following properties are set on
the connection:
CommandTimeout = 0
Connected = True
ConnectionTimeout = 30
ConnectionOptions = coConnectUnspecified
CursorLocation = clUseServer
IsolationLevel = ilCursorStability
LoginPrompt = False
Mode = cmReadWrite
Provider = 'SQLOLEDB'


Thanks

3. Q about olld good TADOConnection (D5)

4. REFORMATTED Is it possible to use TADOConnection with MySQL ADO.NET Connector?

5. Help HOW to Connecting with DTSPackage In TADOConnection?

6. Problem using TADOConnection in thread

7. Database physical connection still open after TADOConnection->Close() is closed.

8. proper useage of TADOConnection in .dll

9. Is TAdoConnection threadsafe??

10. TADOConnection using mixed Authenication

11. TADOConnection.Create fails when called from a service application...

12. TADOConnection LogInPrompt

13. Changing DB with TADOConnection

14. Runtime adding files to database via a TADOConnection - how?

15. TADOConnection and connection lifetime