Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Write to file in SQL Server 2005+
From Wiki
Use this deployed to a designated DBA database set to TRUSTWORHTY and EXTERNAL write contents to a file
Create a C# database project and use the following code
- public class SQLCLRIO
- {
- public static void WriteToFile(String content, String filename)
- {
- try
- {
- File.WriteAllText(filename, content);
- }
- catch (Exception ex)
- {
- SqlContext.Pipe.Send("Error writing to file : " + ex.Message);
- }
- }
- }
Then run the following to create your proc in SQL Server
- CREATE PROCEDURE [dbo].[writetofile]
- @content [nvarchar](max),
- @filename [nvarchar](255)
- WITH EXECUTE AS CALLER
- AS
- EXTERNAL NAME [CLRIO].[SQLCLRIO].[WriteToFile]
--onpnt 13:28, 17 February 2010 (GMT)
LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.