d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Sql Trouble Shooting
Add Reply New Topic New Poll
Member
Posts: 31,343
Joined: Aug 3 2009
Gold: 0.66
Oct 15 2015 11:07am
Anyone familiar with sql want some fg to troubleshoot a script?
Its to pull file attachment into emails
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 15 2015 06:46pm
post the script and describe your problem. nobody is going to run it, so we're just eyeballing it. post whatever useful logging you have as well.
Member
Posts: 31,343
Joined: Aug 3 2009
Gold: 0.66
Oct 16 2015 09:34am
Quote (carteblanche @ Oct 15 2015 07:46pm)
post the script and describe your problem. nobody is going to run it, so we're just eyeballing it. post whatever useful logging you have as well.


I have a script that pulls a file into an email as an attachment and sends it out. It recently has stopped working. The file I am pulling is named "DTH201509240918.xlsx" with the last 4 numbers being random so I use '^.*$'. The files are in the source folder, but I always get "no files found".
ALTER Procedure [dbo].[DSEmail] as begin

declare @to varchar(1000)
,@sub varchar(1000)
,@subdate varchar(10) = CONVERT(Varchar(10),GETDATE(),101)
,@bod varchar(1000)
,@filePath varchar(1000) = '\\source\'
,@fileDate varchar (8) = CONVERT(Varchar(8),GETDATE(),112)
,@attachments varchar(1000)
,@pathAndFile varchar (1000)


Set @attachments = 'DTH' + @fileDate + '^.*$'
Set @pathAndFile = @filePath + @attachments
Set @sub = 'dS Report ' + @subdate
Set @bod = '\\source\' + @attachments


Set @to = 'email@email.com'

IF dbo.fn_FileExists(@pathAndFile) = 1
exec msdb.dbo.sp_send_dbmail
@recipients = @to
,@subject = @sub
,@body = @bod
,@file_attachments = @pathAndFile

ELSE

exec msdb.dbo.sp_send_dbmail
@recipients = @to
,@subject = 'DS Error'
,@body = 'No file was found. Please check \\source\ for today''s file.'

End
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 16 2015 05:46pm
well, sounds like a few things could be off.
1) your path is incorrect
2) the file doesn't exist or has incorrect permissions
3) your regex isn't working

first thing you should do is try hard coding the path without regex. if this works, then it's 1 or 3. if it doesn't work, then it's 2.

sounds like fn_FileExists is your own custom tsql function? sounds like that's the function you should be debugging
Member
Posts: 31,343
Joined: Aug 3 2009
Gold: 0.66
Oct 16 2015 06:12pm
Quote (carteblanche @ Oct 16 2015 06:46pm)
well, sounds like a few things could be off.
1) your path is incorrect
2) the file doesn't exist or has incorrect permissions
3) your regex isn't working

first thing you should do is try hard coding the path without regex. if this works, then it's 1 or 3. if it doesn't work, then it's 2.

sounds like fn_FileExists is your own custom tsql function? sounds like that's the function you should be debugging


N_fileExist is just a normal code to validate a file is there.
I don't think its the regex since this code has worked in the past. The file name has not changed and is still the same.

The path is correct I checked that 3 times.
I will try taking off the regex. Ive been told '^.*$' isn't a good code to use
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 16 2015 06:29pm
Quote (WesWelker @ Oct 16 2015 08:12pm)
N_fileExist is just a normal code to validate a file is there.
I don't think its the regex since this code has worked in the past. The file name has not changed and is still the same.

The path is correct I checked that 3 times.
I will try taking off the regex. Ive been told '^.*$' isn't a good code to use


if it worked in the past but now it's not, then something changed. did you recently change hard drives? did you upgrade your db version? etc etc.

what does "is just a normal code" mean? clearly it's saying the file doesn't exist, so the problem is either with the file, the input params to the function, or the function itself. that should be your starting point.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll