Use XMLHttpRequest to execute a SQL Query and return the results.. help!
I'm building a web app for my company that will run a query every few seconds against SQL Server, and the data that it returns is which database is restoring and how much % complete it is. I have the query already set up and it 开发者_高级运维works fine.
What I want to do is on my Web Form, have a "div" element that will contain the % complete of a database restore, and have it update every few seconds using the JavaScript timer object:
setInterval(function, interval)
I figure I would need to use XMLHttpRequest to send the request to the web server which will run the SQL query. Am I on the right track? How would I even start to do this?
My SQL query is below:
Use master
Select der.session_id, der.command, der.status, der.percent_complete, *
From sys.dm_exec_requests as der
Where percent_complete > 0
Just create a regular ASP.NET page as target for the Ajax request. In the page do all the processing (authentication etc. if necessary) and the DB query as usual. The result you may give back to your JavaScript request via Response.Write(). On the client side, parse the request and display the results.
This is only a very rough overview. Consider using the API which is most apropriate for your data / infrastructure. You may also take into account things like security, JSON/XML etc.
精彩评论