Advertisement

05.08.2008 at 06:22AM PDT, ID: 23385914 | Points: 80
[x]
Attachment Details
Stored procedure results to a CSV file and then email
Tags: c#, .net, ado, sql
We have a requirement to run a SQL Server 2000 stored procedure and then write the results to a CSV file which needs to be emailed. Ideally all this to be automated to be done once daily. Anybody have any ideas?
Thanx
Alexis
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: alexish
Question Asked On: 05.08.2008
Participating Experts: 1
Points: 80
Views: 0
Translate:
Loading Advertisement...
05.08.2008 at 07:06AM PDT, ID: 21524783

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 07:28AM PDT, ID: 21525022

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 07:36AM PDT, ID: 21525092

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 10:14AM PDT, ID: 21526607

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 10:44AM PDT, ID: 21526843

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 07:47AM PDT, ID: 21574220

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 07:58AM PDT, ID: 21574344

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.08.2008 at 07:06AM PDT, ID: 21524783

Rank: Master

Of course.  I do this w/several jobs -- use DTS, a transform data task from server to csv file.  The transform source is your procedure, the destination is the csv file, the transformation is just a 1 to 1 of your proceduer resultset -- i.e., you procedure returns Date,User,Volume -- that's your transformation.

then you've got a sql agent job, 1st step invokes the DTS pkg, like this:
exec master..xp_cmdshell 'DTSRUN /S "servername" /E 'N "packagename" '

the 2nd step in your job is the email.  i do mine like this:

EXEC master..xp_sendmail @recipients ='whomeverYourSendingItto@wherever.com',
@blind_copy_recipients = 'maybeYourself@wherever.com',
@attachments = '\\servername\h$\filename.csv',
@subject='subject line for the email',
@message='any message you'd like to send along with the attachment'



 
05.08.2008 at 07:28AM PDT, ID: 21525022
Interesting approach - let me try and get back to you and with points awarded. It might not be before tomorrow though.

cheers
alexis
 
05.08.2008 at 07:36AM PDT, ID: 21525092

Rank: Master

no worries.  as i said, i'm running a lot of these.  let me know if you need any further info
 
05.08.2008 at 10:14AM PDT, ID: 21526607
Hi there,

The first step running fine apart from a small typo with the N parameter in the syntax - I think it hould read :
exec master..xp_cmdshell 'DTSRUN /S "servername" /E /N "packagename" '

The second one ™ have not had as much joy. The SQL Server agent job appears to run OK but no mail is sent - I kept it simple by not even having an attachment just to make sre that an email can be sent. I seem to remember that there is something that needs to be set up before I can run x_sendmail. Any ideas?

alexis
 
05.08.2008 at 10:44AM PDT, ID: 21526843

Rank: Master

oh yes, i'm sorry, i should have given more detail.  i use smtp and my own version of xp_sendmail.  see here:

/****** Object:  Stored Procedure dbo.xp_sendmail    Script Date: 10/18/2006 9:25:17 AM ******/
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

/****** Object:  Stored Procedure dbo.xp_sendmail    Script Date: 10/18/2006 9:25:17 AM ******/
-- create replacement xp_sendmail procedure
CREATE proc dbo.xp_sendmail
@recipients                   varchar(8000) = NULL,
@message                   varchar(8000) = NULL,
@query                   varchar(8000) = NULL,      -- parameter will not be used
@attachments             varchar(8000) = NULL,
@copy_recipients            varchar(8000) = NULL,
@blind_copy_recipients            varchar(8000) = NULL,
@subject                   varchar(8000) = 'SQL Server Message',
@type                   varchar(8000) = NULL,
@attach_results             varchar(8000) = NULL,      -- parameter will not be used
@no_output                   varchar(8000) = 'FALSE',-- parameter will not be used
@no_header             varchar(8000) = 'FALSE',-- parameter will not be used
@width                   int = 80,            -- parameter will not be used
@separator                   varchar(8000) = NULL,      -- parameter will not be used
@echo_error             varchar(8000) = NULL,      -- parameter will not be used
@set_user                   varchar(8000) = NULL,      -- parameter will not be used
@dbuse                   varchar(8000) = NULL      -- parameter will not be used
as
set nocount on

declare @rc int
exec @rc = master.dbo.xp_smtp_sendmail
      @FROM                  = N'YOURSERVERNAME',   -- change value to suit your own needs
      @FROM_NAME    = N'YOURSERVERNAME',   -- change value to suit your own needs
      @TO                     = @recipients,
      @replyto                  = 'YOURNAME@WHEREVER.COM',       -- change value to suit your needs
      @CC                    = @copy_recipients,
      @BCC             = @blind_copy_recipients,
      @priority                = N'normal',      -- change value to suit your own needs
      @subject           = @subject,
      @message           = @message,        -- no equivalent parameter value available
      @type           = N'text/plain',      -- change value to suit your own needs
      @attachments   = @attachments,      
--      @attach_results  = @attach_results,
      @server       = N'YOURMAILSERVER.COM',  -- change value to suit, like mail.domain.com
      @timeout       = 10000                     -- change value to suit your own needs

if (@@error <> 0 or @rc <> 0)
      raiserror(N'Sending message using xp_sendmail failed', 16, 1)

return @rc
set nocount off

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

 
05.15.2008 at 07:47AM PDT, ID: 21574220
Hi there dbaSQL.
I got sidetracked on another project and will be returning to this tomorrow, so please accept my apologies for the silence - you know how it is.

Many thanx for your input thus far.
Alexis
 
05.15.2008 at 07:58AM PDT, ID: 21574344

Rank: Master

No problem at all, alexish.  I totally know what you mean.  Let me know how it goes.
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628