DSKVP
DSKVP

Reputation: 663

Save XML file in SQL Azure

Could anyone please say me how to declare a column of xml type in sql azure table and also how to save that file from a local computer to the sql azure table?

Thanks in advance :)

Upvotes: 1

Views: 1282

Answers (2)

Daan
Daan

Reputation: 2898

Here is the short answer:

USE YourDataBaseName

GO

CREATE TABLE Something

([SomethingID] INT PRIMARY KEY IDENTITY,

[TheColumnYouWantToDeclare] XML)

GO

With EntityFramework and LINQ to SQL, you can read the xml content and save that to the column. Here is how you can do this. Of course, you can also write SQL queries but here is how I just solved the problem with LINQPAD.

var myEntityToAdd = new Something();

var xmlContent = System.IO.File.ReadAllText(@"C:\NameOfFile.xml");

var xdoc = XDocument.Parse(xmlContent).Root;

myEntityToAdd.TheColumnYouWantToDeclare = xdoc;

Somethings.InsertOnSubmit(myEntityToAdd);

SubmitChanges();

In Azure SQL tables, you can do a lot of things with XML. Here are three videos to help you:

https://channel9.msdn.com/Series/Using-XML-in-SQL-Server-and-Azure-SQL-Database/01 https://channel9.msdn.com/Series/Using-XML-in-SQL-Server-and-Azure-SQL-Database/02 https://channel9.msdn.com/Series/Using-XML-in-SQL-Server-and-Azure-SQL-Database/03

Upvotes: 0

Amar Palsapure
Amar Palsapure

Reputation: 9680

Not the exact answer you are looking for but here what you can do,

  1. Save the file in BLOB, instead Azure Table. BLOB is structure designed for this purpose only.
  2. Secondly, you can store the BLOB url in your Azure Table.
  3. This will make your application easy to understand and also easy to implement.
  4. This will also help in reducing the size of your database, smaller database better performance

Hope this helps you.

Upvotes: 1

Related Questions