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.
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"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.