开发者

ADO error 'Operation cancelled' in Delphi

开发者 https://www.devze.com 2023-01-15 21:27 出处:网络
I have the following code for executing a sql stored procedure that returns multiple resultsets, then reads this result from stream. For background info: it returns xml blocks as strings and then tran

I have the following code for executing a sql stored procedure that returns multiple resultsets, then reads this result from stream. For background info: it returns xml blocks as strings and then transforms it into complete xml. It has worked well over a year but now i have a case that results in error message: Operation cancelled. Debugger shows: Project x raised exception class EOleException with message Operation cancelled. I have no idea whats causing it. Any help or suggestions would be great.

const
  adExecuteStream = $00000400; //Indicates that the results of a command execution should be returned as a stream. 
var
  objCmd, InputStream, XML, XSLT, Template, Processor, objConn, strmResults : Variant;
  ATStreamClass : TMemoryStream;
  Adapt : TStreamAdapter;
  OutputStream: IStream;

objCmd := CreateOLEObject('ADODB.Command');
objCmd.ActiveConnection := dmABaasMock.dbRaAndm.ConnectionObject;
objCmd.CommandType := adCmdText;
objCmd.CommandText := <sp proc开发者_如何学JAVA name with params>;
strmResults := CreateOLEObject('ADODB.Stream');
strmResults.Open;
objCmd.Properties['Output Stream'] := strmResults;
objCmd.Execute(EmptyParam, EmptyParam, adExecuteStream); // HERE COMES THE EXCEPTION
strmResults.Position := 0;
xmlMemo.text := strmResults.ReadText;


Difficult to guess what is going wrong without seeing more.
Three things you can do to get more debugging information:

  • What has changed between when it was working and now? OS version (or ADO), DB, stored proc,...
  • Is the stored proc working when launched directly in the SQL environment?
  • Could you rewrite your code to use the regular ADO components instead of doing late binding and get the results in DataSets instead of an ADODB.Stream OleObject. Only having Variant objects doesn't help much if you need to debug and drill down in the code? You can't debug a black box...


I recently had some strange error message when connecting to ADO, and not having the connection string right.
I'm not 100% sure it was the same error message (sorry, I forgot to take a screenshot back then), but if it is, then this might help:

In .NET, when you connect to ADO and use integrated security, you can specify Integrated Security="True", but using the native providers (not only in Delphi, but from any native environment), you will have to specify Integrated Security="SSPI".

I got into the situation because I was fiddling with connection strings (to connect from Delphi native win32 to a server that I previously connected to from .NET) and forgot to copy just the relevant parts.

--jeroen

0

精彩评论

暂无评论...
验证码 换一张
取 消