1
votes

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?

1
Pretty sure it's not related to your problem, but the way you're creating the connection object is screaming out memory leak. Every time you call that function MyADOConn it creates a new connection instance, and the only reference you keep to it is inside of rsGrid. I hope you're freeing it somewhere later, but even if so, the design is still majorly flawed and can still cause a big leak. - Jerry Dodge
Thanks for mentioning that Jerry, but here is just an example. In my real app the connection object is constructed and freed properly ;) Proven by MadExcept. - Interface Unknown
If you replace your TAdoDataSet with a TAdoQuery, can you successfully open it in the IDE using the Object Inspector? - MartynA
@MartynA, In design-time I can perfectly open both TADODataSet and TADOQuery in Object Inspector. The only problem appears at run-time. - Interface Unknown
In that case, I think it's likely yo be something that only you can debug,but you should be able to easily find out exactly where it is hanging at run-time. Make sure your project has "Use debug DCUs" checked under your project's Debug options, then trace into rsGrid.Active := True. - MartynA

1 Answers

2
votes

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).