Is it possible to stream an XML file to a MS SQL Stored Procedure as a parameter from a C# application without having to load it into memory on the c# end?
The XML files i have are quite large, ~600MB with 2mil entries. Which as you can imagine, takes a bucket load of memory.
Once the SP on SQL inserts/updates values in the database from these files it has no further use for them and can be disposed.
SQL Example:
CREATE PROCEDURE [dbo].[AddAllFromList]
(
@XmlData XML
)
BEGIN
Do something with @XmlData;
END;
C# Example
using (Stream XMLFileStream = new someFileInfo.OpenRead())
using (SqlConnection Connection = new SqlConnection(SQLConnectionString))
{
var opensql = Connection.OpenAsync();
SqlCommand sqlcommand = new SqlCommand("AddAllFromList", Connection)
{
CommandType = System.Data.CommandType.StoredProcedure,
CommandTimeout = 360
};
sqlcommand.Parameters.Add("@XmlData", SqlDbType.Xml).Value = XMLFileStream;
try
{
await sqlcommand.ExecuteNonQueryAsync()
}
catch
{
Console.WriteLine("Failed");
}
Would something like this work? Does anyone have any success stories?
Mapping
thingy-ma-bob (technical term used for describing something for which i have forgotten its name). – Eddie Ted Crocombe Apr 18 '18 at 03:44