I am trying to operate an TADODataSet
in a program on Delphi 10.1 Berlin
Here is my code:
rsGrid.Connection := MyADOConn;
rsGrid.CommandType := cmdText;
rsGrid.CommandText := 'my_StoredProc 100';
rsGrid.IndexName := 'ObjectID';
rsGrid.Active := True; //***** Showstopper here! *****//
while not rsGrid.Eof do
begin
Memo1.Lines.Add(rsGrid.FieldByName('ObjectID').AsString);
rsGrid.Next;
end;
The Connection
property of the DataSet sets up as follows:
function TMainForm.MyADOConn: TADOConnection;
begin
Result := TADOConnection.Create(nil);
with Result do
begin
ConnectionString := 'Provider=SQLNCLI11.1;Persist Security Info=False;User ID=user15;Password=mypassword;Initial Catalog=MyDB;Data Source=my.server.com;Initial File Name="";Server SPN=""'';
KeepConnection := True;
IsolationLevel := ilCursorStability;
Mode := cmUnknown;
LoginPrompt := False;
Connected := True;
end;
end;
The database is SQL Server 2012, so I tried to run it with SQL Server Native Client 10 and 11 (Provider=SQLNCLI10.1
and Provider=SQLNCLI11.1
respectively).
I plan to use this TADODataSet later with a Grid component (via TDataSet) but I couldn't make this thing working In XE8, Seattle and now Berlin. It just hangs on rsGrid.Active := True
. I also tried rsGrid.Open
but it doesn't work as well.
At the same time it perfectly compiles and executes on my XE4. What am I doing wrong in Berlin?
Here is what happened. I am posting it as the answer, so it may help others who port the code from earlier versions of Delphi XE (prior to XE8) to XE8/Seattle/Berlin.
For some reason when you port the forms with TADODataSet component on it, it loses some key attribute(s). In other words, when transferred the component misses some attributes (i.e.
LockType := ltOptimistic
) which are important in my particular case.How To Make It Work
To get your code back to life, simply re-place the
TADODataSet
component on your Form (delete it and place a new one).