Solved

Database accessed through web service or stored procedure

Posted on 2014-03-18
6
300 Views
Last Modified: 2014-03-18
I have a grid that is populated and displays the data to a grid.

WEBSERVICE:
Is there a benefit to passing the ad hoc query that populates that grid to a web service and returning an object? This has been a recommendation. But when stepping through the code, the spinner spins when the grid is actually populated with the datasource:
grdSelector.DataSource = blah

So I don't really see a benefit of using the webservice to speed up the grid load. But I just don't know.

STORED PROCEDURE:
I do use stored procedures for all CRUD operations other than populating grids based on search criteria. When the query is built from search criteria, I use the ad hoc query to a SQLCommand to a DataTable.

What is your opinion on taking my query and putting it in a stored procedure instead of an ad hoc query using a SQL Command to a DataTable?

(The query is extremely huge and detailed based on numerous tables and where clauses, inner joins, etc. The query changes depending on the search criteria selected by the user running the report.)

Thanks!
0
Comment
Question by:Starr Duskk
  • 3
  • 3
6 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 500 total points
ID: 39937776
"The query is extremely huge and detailed based on numerous tables and where clauses, inner joins, etc. The query changes depending on the search criteria selected by the user running the report."

Best candidate in my opinion for a SQL Stored proc in my opinion and please use use the EXEC sp_executesql inside it not just the EXEC commands for the dynamic code built inside it.
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39937857
If I were to build the sql query string in my code, and then pass the entire value to a stored procedure as a string and execute it there, would that be of any benefit?

Something like this:

ALTER Procedure [dbo].[prBuildSQL]
		@chvSQL text
As
	EXEC (@chvSQL)

Open in new window


(But I'd want to return a DataTable.)

Because there are so many filters and criteria for this final query and it looks up values depending who the logged in user is as it builds the query. It is a monster that changes dependent upon so many filters and report type and logged in user and their role and everything.

thanks.
0
 
LVL 40

Expert Comment

by:lcohan
ID: 39937889
"If I were to build the sql query string in my code, and then pass the entire value to a stored procedure as a string and execute it there, would that be of any benefit?"

Not really - why not vice versa? You have the SQL SP that takes input parameters from your UI code then based on those builds the dynamic code that will in the end "(But I'd want to return a DataTable.)" - that's what a SQL Stored Proc does - returns a data set (or more - see MARS).
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 2

Author Comment

by:Starr Duskk
ID: 39938070
Okay, what about a web service?
0
 
LVL 40

Expert Comment

by:lcohan
ID: 39938083
In my view it is the same thing and is just different way/method to call the SQL Stored Procedure passing the parameter values and getting back the desired record set.
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 39938131
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question