Solved

Database accessed through web service or stored procedure

Posted on 2014-03-18
6
294 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:BobCSD
  • 3
  • 3
6 Comments
 
LVL 39

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 1

Author Comment

by:BobCSD
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 39

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:BobCSD
ID: 39938070
Okay, what about a web service?
0
 
LVL 39

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 1

Author Closing Comment

by:BobCSD
ID: 39938131
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now