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 2000 Forums
 SQL Server Development (2000)
 Sending Attachements which is saved in database

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-08-31 : 10:31:05
Vinu writes "i have an application in c# which has a requirement of sending mails to all employees. I have some files in pdf format which is savedin sqlserver and the coloumn type is "image". I need to send the actucal file saved in the database as attachment to the employees. I can send the emails from the client pc but sending mail with attachment is very slow and so it is time consuming. I need to know how can i retrieve the files from the image column in the sqlserver and send the file as attachemnt from the stored procedure."

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-08-31 : 13:08:13
I would think a c# solution would be preferable to a sql solution but...I've never done this but it looks like xp_sendmail can do this:

exec master..xp_sendmail
@recipients = '<send-to address>'
,@query = '<query to retrive image column value>'
,@attachments = '<This will be the attached file name.pdf>'
,@attach_results = 'TRUE'


Be One with the Optimizer
TG
Go to Top of Page

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2006-08-31 : 14:39:35
TG,

That won't do what he asked (I don't know how to do that either). Your code omits the part where the SQL code has to save the image column's data to file in "This will be the attached file name.pdf" before your code will work.

Ken
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-31 : 14:44:37
You can't use SQL Mail for this as SQL can't get the image data to a file. You must do this in your application code. Use CDO to send the e-mail.

Tara Kizer
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-08-31 : 14:53:30
I believe you guys that sql won't know how to save the image data as a file. This made it seem possible to me that sql could do the necessary magic to save the image as a file:
quote:

from books online - xp_sendmail

[@attach_results =] 'attach_value'

Is an optional parameter specifying the result set of a query should be sent in mail as an attached file instead of being appended to the mail. If attachments is not NULL and attach_results is true, the first file name in attachments is used as the file name for the results. If attachments is NULL, a file name is generated with a .txt extension. The default is FALSE, which means that the result set is appended to the message.



Be One with the Optimizer
TG
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-31 : 15:03:03
That just saves the results of a query to a file. So the file would have the same thing that we'd see in Query Analyzer if we viewed the image data.

Tara Kizer
Go to Top of Page
   

- Advertisement -