views:

43

answers:

1

I have asp.net 3.5 C# and a SQL Server 2008 back end.

There is a table that I use the most, this table has around 100 rows and doesn't change often. My code (web service with a cache) is called from JQuery to search a record by ID and return a JSON response to client side.

Recently the server that hosts my site had a big problem and had to migrate to a new server and my site was down for 3 days. I started thinking, to save my data to a XML, or Json file and do not touch the database anymore.

I need your input. I know how to work with the XML file (I will use the LINQ), but don’t know how to read a JSON file from the client side with JQUERY. Maybe I should read it on server side as StreamReader?

Which method do you like better (XML, or JSON). Any help would be greatly appreciated.

+2  A: 

You can actually call an AJAX query right to a JSON file and it'll work from jQuery. This is known as a RESTfull api.

For instance:

http://www.myserver.com/api/customers/12

Could be a file 12 in the foler api/customers or it could be a script returning a json response. The idea is that the url represents the resource you're looking for.

However I highly suggest you don't go this approach, even if you load down the 100 rows and search for it in javascript it's a bad idea, as it'll put load on the client and defeats the purpose of AJAX (To only retrieve relevant information).

If you're determined to do away with your database I would suggest using an xml file, as you keep the processing on the server-side and and ensure it's behaviour. Any code that runs on the client is subject to:

  1. Tampering
  2. Version Issues
  3. Taint from plugins

It's also harder to debug.

I suggest exposing a method on your webservice that looks up the row by ID, and then uses a simple LINQ to XML query to retrieve the data you want.

ID search should be very simple, and you could even cache the results if you're getting hit hard (to reduce disk reads & xml parses), but that may be overkill :)

Aren
Thank you for your suggestion. it was really helpful
FrenchiInLa
You're welcome :)
Aren