Temporary File is not deleted from {TempDir}

Discuss RoboTask here
Post Reply
sarnusch
Posts: 63
Joined: Thu Apr 28, 2022 9:05 am

Temporary File is not deleted from {TempDir}

Post by sarnusch »

Good morning,
I recognized an issue with action 'SQL Query to CSV file'.

I want to create a CSV file from sql data and then (if it exists) send it to an email-address.
I am using for example {TempDir}\test.csv as target file for the query results.

In the first run I have a result set and the email is sent with the correct CSV file in attachement.
The second run does have an empty result set but the email is sent with the file from the first run.

I checked 'Do not create file if query result is empty' but I assumed that files in temporary folder are deleted after the task ends properly.
I do not want to send empty files.
I also check if the file exists with '{FileExists({TempDir}\test.csv)}'. In my opinion this check should not find the file in the second run.

Code: Select all

I: 13.06.2025 08:34:50: ****** Starting task: Test TEMP Datei ******************
I: 13.06.2025 08:34:50: Executing "1.SQL Query to CSV File"
I: 13.06.2025 08:34:50: Executing "2.If Then"
I: 13.06.2025 08:34:50: Executing "3.SMTP Send Email"
I: 13.06.2025 08:34:50: Executing "4.Else"
I: 13.06.2025 08:34:50: Task executed successfully
I: 13.06.2025 08:35:14: ****** Starting task: Test TEMP Datei ******************
I: 13.06.2025 08:35:14: Executing "1.SQL Query to CSV File"
W: 13.06.2025 08:35:14: The query returned an empty recordset
I: 13.06.2025 08:35:14: Executing "2.If Then"
I: 13.06.2025 08:35:14: Executing "3.SMTP Send Email"
I: 13.06.2025 08:35:14: Executing "4.Else"
I: 13.06.2025 08:35:14: Task executed successfully
I am using latest version:
RoboTask version 10.4.0.1192 (x64 edition)
Assembly version 10.4.0.316

This is my task:

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1199727700
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task41"
Hide=INTEGER|0
ID=INTEGER|-541250406
LogOnAsUser=INTEGER|1
Name=STRING|"Test TEMP Datei"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RestrictRESTAPIAccess=INTEGER|0
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER

[Actions\Action1]
ActionID=STRING|"A_CSVFROMSQL"
Enabled=INTEGER|-1
Name=STRING|"SQL Query to CSV File"
Params=FOLDER

[Actions\Action1\Params]
connectionstring=STRING|"Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=;Initial Catalog=;Data Source="
customdateformat=STRING|"0"
dateformat=STRING|"yyyy-mm-dd hh:nn:ss"
delimiter=STRING|"2"
limitlength=STRING|"999"
notcreateifempty=STRING|"1"
override=STRING|"0"
paramcount=STRING|"0"
password=STRING|""
quotechar=STRING|"0"
sql=STRING|""
strictdelimiter=STRING|"1"
targetencoding=STRING|"0"
targetfilename=STRING|"{TempDir}\test.csv"
timeout=STRING|"60"
usefieldnames=STRING|"1"
uselimitlength=STRING|"1"
withmemo=STRING|"1"

[Actions\Action2]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action2\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{FileExists({TempDir}\test.csv)}"

[Actions\Action3]
ActionID=STRING|"A_INET_SENDMAIL"
Enabled=INTEGER|-1
Name=STRING|"SMTP Send Email"
Params=FOLDER

[Actions\Action3\Params]
attach0=STRING|"{TempDir}\test.csv"
attachcount=STRING|"1"
auth=STRING|"0"
charset=STRING|"windows-1250"
from=STRING|""
host=STRING|""
html=STRING|"1"
msg0=STRING|"<html>"
msg1=STRING|"<body>"
msg8=STRING|"</body>"
msg9=STRING|"</html>"
msgcount=STRING|"10"
password=STRING|""
port=STRING|""
priority=STRING|"1"
receipt=STRING|"0"
SSL=STRING|"0"
subject=STRING|"Test"
tlsmode=STRING|"0"
tlsver=STRING|"2"
to=STRING|""
user=STRING|""
xmailer=STRING|"RoboTask"

[Actions\Action4]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action5]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action5\Params]
message=STRING|"Keine Daten vorhanden"
type=STRING|"3"

[Actions\Action6]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
Oleg
Site Admin
Posts: 3217
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Temporary File is not deleted from {TempDir}

Post by Oleg »

Just remove file before SQL query.
Like this

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|307868550
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1466"
Hide=INTEGER|0
ID=INTEGER|-541250406
LogOnAsUser=INTEGER|1
Name=STRING|"Test TEMP Datei (corrected)"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RestrictRESTAPIAccess=INTEGER|0
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""_CsvFile"" with value ""{TempDir}\test.csv"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"_CsvFile"
expand=STRING|"1"
linecount=STRING|"1"
varname=STRING|"_CsvFile"
varvalue=STRING|"{TempDir}\test.csv"

[Actions\Action2]
ActionID=STRING|"A_FILE_DELETE"
Enabled=INTEGER|-1
Name=STRING|"Delete File"
Params=FOLDER

[Actions\Action2\Params]
Count=STRING|"1"
deletedirs=STRING|"0"
deletereadonly=STRING|"0"
file0=STRING|"{_CsvFile}"
hidden=STRING|"1"
subdir=STRING|"0"
system=STRING|"1"
ToRecycleBin=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_CSVFROMSQL"
Enabled=INTEGER|-1
Name=STRING|"SQL Query to CSV File"
Params=FOLDER

[Actions\Action3\Params]
connectionstring=STRING|"Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=;Initial Catalog=;Data Source="
customdateformat=STRING|"0"
dateformat=STRING|"yyyy-mm-dd hh:nn:ss"
delimiter=STRING|"2"
limitlength=STRING|"999"
notcreateifempty=STRING|"1"
override=STRING|"0"
paramcount=STRING|"0"
password=STRING|"P6m8mu0ChGWAUczO5BVcnH5wYxpb4H6EmFndLP2BRmkO9ZAscL07XVk="
quotechar=STRING|"0"
sql=STRING|"""Put SQL here"""
strictdelimiter=STRING|"1"
targetencoding=STRING|"0"
targetfilename=STRING|"{_CsvFile}"
timeout=STRING|"60"
usefieldnames=STRING|"1"
uselimitlength=STRING|"1"
withmemo=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action4\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{FileExists({TempDir}\test.csv)}"

[Actions\Action5]
ActionID=STRING|"A_INET_SENDMAIL"
Enabled=INTEGER|-1
Name=STRING|"SMTP Send Email"
Params=FOLDER

[Actions\Action5\Params]
attach0=STRING|"{TempDir}\test.csv"
attachcount=STRING|"1"
auth=STRING|"0"
charset=STRING|"windows-1250"
html=STRING|"1"
msg0=STRING|"<html>"
msg1=STRING|"<body>"
msg8=STRING|"</body>"
msg9=STRING|"</html>"
msgcount=STRING|"10"
priority=STRING|"1"
receipt=STRING|"0"
SSL=STRING|"0"
subject=STRING|"Test"
tlsmode=STRING|"0"
tlsver=STRING|"2"
xmailer=STRING|"RoboTask"

[Actions\Action6]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action7]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action7\Params]
message=STRING|"Keine Daten vorhanden"
type=STRING|"3"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

Oleg Yershov
Post Reply