views:

78

answers:

2

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 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;
+2  A: 

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...
François
The thing is that its still works for everybody else, its a single case for one user and data. I've had problems with stored proc very big results, timeouts, but in this case there isnt much data also. So, nothing has changed, stored proc works fine when executed from Management studio, i do have to rewrite the code at some point when nothing else helps but this still works in 99,99% of time.
Tamm
@Tamm. "its a single case for one user and data..." Can you separate user and data to see if it is linked to the data or the user (or the computer). That would help to know if it's linked to this DB or some user's set-up.
François
So, its not linked to user. I ran it on my own computer and same result: EOleException, Operation canceled. The error was raised in DispCallError procedure in Delphi's ComObj unit. So it must be data related problem? I have no easy way to divide data into smaller portions to investigate, more like close to impossible.
Tamm
@Tamm. Is the stored proc still working fine in Management studio for this exact set of data?
François
Yes, thats why i think problem is with ADO. The last line in Delphi's stack window is DispCallError(-2147352567, (0, 0, 'Microsoft SQL Native Client', 'Operation canceled', '', 0, nil, nil, -2147217887), nil, False).
Tamm
+1  A: 

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

Jeroen Pluimers
Thanks for your answer, connection string can be a headache but this cant be the case here. Theres no problem with the connection, stored proc is executed correctly and the connection still works afterwards too.
Tamm
OK; What is the exact exception (exception class, exception message, exception properties if it is something that has a list of errors)? I guess you use SQL Server; did you run a trace there to see if the error is on the server or on the ADO side?
Jeroen Pluimers
I ran a trace, the error is not on the server side. EOleException, Operation canceled. The error was raised in DispCallError procedure in Delphi's ComObj unit. The last line in stack window is DispCallError(-2147352567, (0, 0, 'Microsoft SQL Native Client', 'Operation canceled', '', 0, nil, nil, -2147217887), nil, False).
Tamm