|
sql
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Logging from SPHi,
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 Consider creating a CLR stored procedure (which does the logging) which you can call from your
procedures. -- Show quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://sqlblog.com/blogs/tibor_karaszi "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 On Nov 21, 10:56 pm, Mohit K. Gupta <mohitkgu***@msn.com> wrote:
> Hi, There are few ways to write an output file from a stored procedure.> > 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 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 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 > |
|||||||||||||||||||||||