Home All Groups Group Topic Archive Search About
Author
21 Nov 2007 8:56 PM
Mohit K. Gupta
Hi,

   Is there a way I can log to a output file from a SP when executed from
with in an application?

--
Mohit K. Gupta
B.Sc. CS, Minor Japanese
MCTS: SQL Server 2005

Author
22 Nov 2007 7:43 AM
Tibor Karaszi
Consider creating a CLR stored procedure (which does the logging) which you can call from your
procedures.

Show quote
"Mohit K. Gupta" <mohitkgu***@msn.com> wrote in message
news:A41E6E64-FA1E-4642-BCEC-B44FC342BCF9@microsoft.com...
> Hi,
>
>   Is there a way I can log to a output file from a SP when executed from
> with in an application?
>
> --
> Mohit K. Gupta
> B.Sc. CS, Minor Japanese
> MCTS: SQL Server 2005
Author
22 Nov 2007 7:51 AM
Adi
On Nov 21, 10:56 pm, Mohit K. Gupta <mohitkgu***@msn.com> wrote:
> Hi,
>
>    Is there a way I can log to a output file from a SP when executed from
> with in an application?
>
> --
> Mohit K. Gupta
> B.Sc. CS, Minor Japanese
> MCTS: SQL Server 2005

There are few ways to write an output file from a stored procedure.
Most of the ways have some security issues.  For example you can use
xp_cmdshell with BCP.  Another way is to use xp_cmdshell with DTSRun
utility.  You can also use com objects and the sp_oa* stored
procedures.   Another way is to write whatever you want to log into a
table and then have a scheduled job export the table into a file. This
is the easiest way and it has no security problems, but since I don't
know your requirements, I don't know if you can use this method.  If
you are using SQL Server 2005 you could write a CLR procedure that
writes the output to the disk.

Adi
Author
24 Nov 2007 3:21 AM
Sean McCown
I both agree and disagree with the statements here.
While Adi is right, those are all valid methods for logging inside an SP, I
caution you against pushing the code to the CLR for the sole purpose of
gaining easier logging.  The CLR is for specific cases, and I don't think
logging is one of them. 
Personally, I like Adi's table method best.  It's easy, robust and
accessable from all outside sources.
The CLR solution however could cause more problems than it solves if you're
not careful.




Show quote
"Adi" wrote:

> On Nov 21, 10:56 pm, Mohit K. Gupta <mohitkgu***@msn.com> wrote:
> > Hi,
> >
> >    Is there a way I can log to a output file from a SP when executed from
> > with in an application?
> >
> > --
> > Mohit K. Gupta
> > B.Sc. CS, Minor Japanese
> > MCTS: SQL Server 2005
>
> There are few ways to write an output file from a stored procedure.
> Most of the ways have some security issues.  For example you can use
> xp_cmdshell with BCP.  Another way is to use xp_cmdshell with DTSRun
> utility.  You can also use com objects and the sp_oa* stored
> procedures.   Another way is to write whatever you want to log into a
> table and then have a scheduled job export the table into a file. This
> is the easiest way and it has no security problems, but since I don't
> know your requirements, I don't know if you can use this method.  If
> you are using SQL Server 2005 you could write a CLR procedure that
> writes the output to the disk.
>
> Adi
>

AddThis Social Bookmark Button