0

I have a problem with the Delphi database components. I tried to add some functionality to a program, but was getting strange problems. I broke it down to a simple sample project and the behaviour is still there.

I created a new Forms Application on Delphi 2007, added a TSQLConnection, TSQLTable, TDataSetProvider and TClientDataSet. I inserted the information for a local MS SQL database and the table that is inside, which is a simple test table:

CREATE TABLE dbo.Test1(
[Name] varchar(32) not null primary key,
[Type] varchar(16) not null,
[Selected] BIT not null)

I then added a TEdit, TListBox and 2 Buttons. The function should be: Press Add and a record with the name of Edit1 is entered into the database. Press Update and the listview gets filled with the entries already in the database.

The code:

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
  ClientDataSet1.Refresh;
  ClientDataSet1.First;
  while not ClientDataSet1.Eof do
  begin
    ListBox1.AddItem(ClientDataSet1Name.AsString,nil);
    ClientDataSet1.Next;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ClientDataSet1.Append;
  ClientDataSet1Name.AsString := Edit1.Text;
  ClientDataSet1Type.AsString := 'A1';
  ClientDataSet1Selected.AsBoolean := false;
  ClientDataSet1.Post;
  ClientDataSet1.ApplyUpdates(-1);
end;

Now the strange thing for me is, that when start the program, add 2 records (checked in management studio that they are really there) and now i click on update, the list stays empty, as the RecordCount of the ClientDataSet is 0 as soon as the Refresh on begin of Button1Click is executed. The entries however are and stay in the database.

The other strange thing is, that as soon as i quit the program, and start it again and try to add another record, i get the error "Cannot create new connection because in manual or distributed transaction mode". As soon as i delete the records from the table and restart the program, I can add again.

Can someone tell me how this strange behaviour happens and how i can fix it?

Thanks in advance.

jachguate
  • 16,976
  • 3
  • 57
  • 98
Marks
  • 3,613
  • 5
  • 31
  • 46
  • Ok, i found out that the first problem does not happen if i call SQLTable1.Refresh before ClientDataSet1.Refresh. But i thought this is something the DataSet should do itself. – Marks Jan 15 '13 at 12:31
  • For the refresh, is your SQLTable1 closed at program startup? It is documented for the provider that if the base dataset is open it doesn't open it again. – jachguate Jan 15 '13 at 16:05
  • No, the SQLTable1 is open. I checked it. Also if it was closed i couldn't do the Refresh since this gives an error if the Table is closed. – Marks Jan 16 '13 at 08:21
  • let the table closed and work on the ClientDataSet to refresh the records. – jachguate Jan 16 '13 at 15:06

1 Answers1

0

Maybe this one:

"Problem:
When using the MSSQL dbExpress driver with a ClientDataSet and a Provider, keep getting the following error when calling ApplyUpdate: Cannot create new connection because in manual or distributed transaction mode

Suggested Work Around:
Set "poFetchDetailsOnDemand" (for the Provider) to False. This is a known issue when it is set to True."

(Quoted from this Embarcadero article which refers to SQLOLEDB Allows Only One Connection in Scope of Transaction.

There's a lof of search results for "Cannot create new connection because in manual or distributed transaction mode"

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
  • The poFetchDetailsOnDemand is on False like it was already per default. I know there are a lot of search results, but i have already looked through at least the first 4 pages of google and tried.Nothing helped. – Marks Jan 15 '13 at 14:01