Hi all,
This has me stumped. I have a service application that is adding to the system Event Log (seen via eventvwr.exe) with the relevent part that reads: "Dataset not in edit or insert mode."
It's occuring seemingly as a result of freeing a TMemoryStream object that was used to retrieve a blob field from an Access database, so there is some sort of sanity about it - I just can't figure exactly what that is.
Some code:
The two LogMessage lines there I've used to trap the offending message - it appears in the Event Log between these two trap logs.
One other weird thing is that in the Event Log, my two trap logs have a Source of 'DocPrint' (which is the value of the TService.Name property), while the offending log message has a Source of 'DocPrintSvc.exe', which is the filename of the service.
The purpose of the code block is to save the contents of a database blob field to a text file. The _ReplaceDestination procedure changes a couple of entries in the TMemoryStream (it contains text strings only).
I'm not sure what else I can say - any clues anyone?
This has me stumped. I have a service application that is adding to the system Event Log (seen via eventvwr.exe) with the relevent part that reads: "Dataset not in edit or insert mode."
It's occuring seemingly as a result of freeing a TMemoryStream object that was used to retrieve a blob field from an Access database, so there is some sort of sanity about it - I just can't figure exactly what that is.
Some code:
Code:
[navy][i]// for automatic syntax highlighting see faq102-6487
[/i][/navy][b]function[/b] TDocPrint.ProcessTransactions: Boolean;
[b]procedure[/b] _ReplaceDestination(AStream: TMemoryStream);
[b]var[/b]
sl : TStringList;
c : Integer;
[b]begin[/b]
sl := TStringList.Create;
[b]try[/b]
sl.LoadFromStream(AStream);
[b]for[/b] c := [purple]0[/purple] [b]to[/b] sl.Count - [purple]1[/purple] [b]do[/b]
[b]begin[/b]
[b]if[/b] SameText(LeftStr(sl[c], [purple]11[/purple]), [teal]' Printer ='[/teal]) [b]then[/b]
sl[c] := Format([teal]' Printer = '[/teal][teal]'%s'[/teal][teal]''[/teal], [qry.FieldByName([teal]'Printer'[/teal]).AsString]);
[b]if[/b] SameText(LeftStr(sl[c], [purple]9[/purple]), [teal]' Email ='[/teal]) [b]then[/b]
sl[c] := Format([teal]' Email = '[/teal][teal]'%s'[/teal][teal]''[/teal], [qry.FieldByName([teal]'Email'[/teal]).AsString]);
[b]end[/b];
AStream.Clear;
sl.SaveToStream(AStream);
[b]finally[/b]
sl.Free;
[b]end[/b];
[b]end[/b];
[b]var[/b]
qry : TADOQuery;
m : TMemoryStream;
p : String;
[b]begin[/b]
Result := False;
p := ExtractFilePath(ParamStr([purple]0[/purple]));
qry := CreateDBQuery([teal]'SELECT * FROM Queue '[/teal]
+ [teal]'WHERE (Printed is Null) AND (NextRetry<=Now()) '[/teal]
+ [teal]'ORDER BY ID'[/teal]);
[b]try[/b]
[b]try[/b]
qry.Open;
qry.First;
Result := [b]not[/b] qry.EOF;
[b]if[/b] Result [b]then[/b]
[b]begin[/b]
[navy][i]// ... snip ...
[/i][/navy] m := TMemoryStream(qry.CreateBlobStream(qry.FieldByName([teal]'Blob'[/teal]), bmRead));
[b]try[/b]
_ReplaceDestination(m); [navy][i]// pretty sure this is not causing any issues[/i][/navy]
m.SaveToFile(p + [teal]'printing.txt'[/teal]);
LogMessage([teal]'trap 1'[/teal]);
[b]finally[/b]
m.Free; [navy][i]// this line must be causing the event
[/i][/navy] [b]end[/b];
LogMessage([teal]'trap 2'[/teal]);
[b]end[/b];
[navy][i]// ... snip ...
[/i][/navy] [b]except[/b]
[b]on[/b] E: Exception [b]do[/b]
LogErr([teal]'ProcessTransactions'[/teal], E); [navy][i]// logs to database
[/i][/navy] [b]end[/b];
[b]finally[/b]
qry.Free;
[b]end[/b];
[b]end[/b];
The two LogMessage lines there I've used to trap the offending message - it appears in the Event Log between these two trap logs.
One other weird thing is that in the Event Log, my two trap logs have a Source of 'DocPrint' (which is the value of the TService.Name property), while the offending log message has a Source of 'DocPrintSvc.exe', which is the filename of the service.
The purpose of the code block is to save the contents of a database blob field to a text file. The _ReplaceDestination procedure changes a couple of entries in the TMemoryStream (it contains text strings only).
I'm not sure what else I can say - any clues anyone?