Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 trigger and file attachment

Author  Topic 

pyromelana
Starting Member

23 Posts

Posted - 2009-03-04 : 07:15:06
Hi!

I am pretty new to triggers, some easy ones work without problem.. but now I have a problem:

I have a table with customers and if there is an update or insert in the table I get an email with C_Nr and C_Name - that works fine. But I want to send a file with the trigger. First of all I don't care about what kind of attachment... as long as I get this dam* attachment.


ALTER TRIGGER [dbo].[NewCustomer]

ON [dbo].[YKUN4015]

FOR INSERT,UPDATE

AS

declare @INTNR varchar(10)
declare @Name1 varchar(50)
declare @message varchar(500)

declare @query_attachment_filename nvarchar(255)
declare @file_attachments nvarchar(max)

SET @INTNR =(SELECT INTNR FROM inserted)
SET @Name1 =(SELECT Name1 FROM inserted)
SET @message='New Customer with Number '+@INTNR+' and name '+@Name1+''

EXEC msdb..sp_send_dbmail

@recipients = 'mymail@mail.com',

@subject = 'New Customer in DB',

@body = @message,

@file_attachments = 'J:\testdatei.txt';


I only get an error message like attachment is not valid... it is on the same Server/Harddisk like the database...

Can anyone help me?

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-03-04 : 10:26:17
  • could this be a security issue, does whatever this is running under have rights to J:
  • Is there a file called testdatei.txt in J:
  • Have you tried UNC Pacth \\Server\testdatei.txt

2 cents
Go to Top of Page

pyromelana
Starting Member

23 Posts

Posted - 2009-03-05 : 01:53:51
1. yes, I have all rights (and the trigger runs on the sql-server)
2. yes, the testdatei.txt is on the server
3. no, I will try this and post my result
Go to Top of Page

pyromelana
Starting Member

23 Posts

Posted - 2009-03-05 : 09:49:52
you are absolutely right - the UNC path is the important thing...

@file_attachments = '\\R*****r-sql\I******T\testdatei.txt'; and

everything works. Perfect!
Go to Top of Page
   

- Advertisement -