简体   繁体   English

柏林Delphi 10.1上的TADODataSet问题。 查询挂起

[英]Issue with TADODataSet on Delphi 10.1 Berlin. Query hangs

I am trying to operate an TADODataSet in a program on Delphi 10.1 Berlin 我正在尝试在Delphi 10.1 Berlin上的程序中操作TADODataSet

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: 数据集的Connection属性设置如下:

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). 该数据库是SQL Server 2012,因此我尝试使用SQL Server Native Client 10和11(分别为Provider=SQLNCLI10.1Provider=SQLNCLI11.1 )运行该数据库。

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. 我计划以后将这个TADODataSet与Grid组件一起使用(通过TDataSet),但是我无法在XE8,西雅图和现在的柏林使用此工具。 It just hangs on rsGrid.Active := True . 它只是挂在rsGrid.Active := True I also tried rsGrid.Open but it doesn't work as well. 我也尝试了rsGrid.Open但效果不佳。

At the same time it perfectly compiles and executes on my XE4. 同时,它可以完美地在我的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. 我将其发布为答案,因此它可能会帮助将代码从早期版本的Delphi XE(XE8之前的版本)移植到XE8 / Seattle / Berlin的其他人。

For some reason when you port the forms with TADODataSet component on it, it loses some key attribute(s). 由于某些原因,当您移植带有TADODataSet组件的表单时,它会丢失一些关键属性。 In other words, when transferred the component misses some attributes (ie LockType := ltOptimistic ) which are important in my particular case. 换句话说,在传输组件时,会丢失一些属性(即LockType := ltOptimistic ),这些属性在我的特定情况下很重要。

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). 为了使您的代码恢复TADODataSet ,只需将TADODataSet组件重新放置在您的Form上(删除它并放置一个新组件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM