SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


CLR procedure to export xml file ?


CLR procedure to export xml file ?

Author
Message
the.rahmony
the.rahmony
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 9
GSquared (12/21/2011)
I'm not exactly expert at CLR, but I've bumbled my way through writing a text file using VB.NET's file operations just by digging through Bing searches on the subject. It's not that hard to do. I can't remember how I did it (was 3 years ago), but I remember it not being particularly difficult. Writing an XML file should be easy enough, unless you have oddball requirements.

Have you thought about simply having SSIS export the file instead? That'll be even easier.

thank you


Cadavre (12/21/2011)
Totally untested, I'm not at my desk any more.

using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using System;
using System.IO;

namespace XMLWriter
{
public class XMLWriter
{
[SqlFunction]
public static SqlString ReplaceMatch(
SqlString inputXMLString,
SqlString outputFileDIR)
{
try
{
// input parameters must not be NULL
if (!inputXMLString.IsNull &&
!outputFileDIR.IsNull)
{
System.IO.StreamWriter file = new System.IO.StreamWriter(outputFileDIR);
file.WriteLine(inputXMLString);
file.Close();
}
else
// if any input paramater is NULL, return NULL
return SqlString.Null;
}
catch
{
// on any error, return NULL
return SqlString.Null;
}
return new SqlString();
}
};
}


will give it a try thx buddy Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search