Showing posts with label selects. Show all posts
Showing posts with label selects. Show all posts

Thursday, March 8, 2012

Caching of stored procedure

Hello all,

I've got an application that calls a really simple stored procedure - just selects all records from the dbase. The problem is this seems to cache every now and then and as the same table is updated very frequently by other users this means the data returned isn't up to date. I thought it was Sql Server caching the results of the stored procedure, but I can do an iisreset and it will be up to date again. And unless I'm missing some point iisreset has no bearing on Sql Server. So is there an application data cache somewhere that I should be clearing to ensure the recordset is always up to date?

The question that comes immediately to my mind is.. Are you storing the data from the database in some state bags.. like Session state or Application State or.. simply any application caching?

The problem obviously lies with your application... not any sql server caching.. So, how do you retrieve the data that your application use? Make a fresh database call everytime you read that data?

|||

Hi,
I was being stupid - I wasn't storing the data in state but I was using paged data and my page number was referenced statically so whenever one user moved the page on everyone saw the older pages!

Doh!

Tuesday, February 14, 2012

business logic in Stored Proc VS aspx.vb page

Hello,

I stuck in a delimma.
Where to put the business logic that involves only one update
but N number of selects from N tables......with N where conditionsHi

In general I would put this in the middle tier or the database. Allowing
direct access to tables from a client would raise security issues and make
it less managable.

John

"A.V.C." <yhspl_softwaregroup@.hotmail.com> wrote in message
news:d28fa5d0.0407060443.2797e77@.posting.google.co m...
> Hello,
> I stuck in a delimma.
> Where to put the business logic that involves only one update
> but N number of selects from N tables......with N where conditions|||A.V.C. (yhspl_softwaregroup@.hotmail.com) writes:
> I stuck in a delimma.
> Where to put the business logic that involves only one update
> but N number of selects from N tables......with N where conditions

I am of the school that puts as much as possible of the business logic
in the stored procedures. The idea is to put the logic where the data is.
If you put logic in the middle tier, you may have a lot network traffic.

The one case where the middle layer is a better place, is when you
have computations that are very intensive on reports. Then you can
take off load from SQL Server, and you can more easilyu scale out.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns951EF3408DA66Yazorman@.127.0.0.1...
> A.V.C. (yhspl_softwaregroup@.hotmail.com) writes:
> > I stuck in a delimma.
> > Where to put the business logic that involves only one update
> > but N number of selects from N tables......with N where conditions
> I am of the school that puts as much as possible of the business logic
> in the stored procedures. The idea is to put the logic where the data is.
> If you put logic in the middle tier, you may have a lot network traffic.

Which would not have otherwise existed if the logic is internal
to the database stored procedure.

> The one case where the middle layer is a better place, is when you
> have computations that are very intensive on reports. Then you can
> take off load from SQL Server, and you can more easilyu scale out.

Where separate pre-processing (ie: regeneration of the computed
values) into a work table is feasible, then this can allow the logic to
be retained in SQL because the realtime computations have been
reduced.|||THanx
Could you pls elaborate the scenario where middle tier is ideal for business logic ?

Erland Sommarskog <esquel@.sommarskog.se> wrote in message news:<Xns951EF3408DA66Yazorman@.127.0.0.1>...
> A.V.C. (yhspl_softwaregroup@.hotmail.com) writes:
> > I stuck in a delimma.
> > Where to put the business logic that involves only one update
> > but N number of selects from N tables......with N where conditions
> I am of the school that puts as much as possible of the business logic
> in the stored procedures. The idea is to put the logic where the data is.
> If you put logic in the middle tier, you may have a lot network traffic.
> The one case where the middle layer is a better place, is when you
> have computations that are very intensive on reports. Then you can
> take off load from SQL Server, and you can more easilyu scale out.|||A.V.C. (yhspl_softwaregroup@.hotmail.com) writes:
> Could you pls elaborate the scenario where middle tier is ideal for
> business logic ?

Permit me to take an example from the system I work with, which is abour
securities trading. When a deal comes in there are a couple of computations
to carry out give the basics: price and the quantity. Most of these
computations are simple: price * qty gives your the purchase amount, and
then you compute charges. And to compute charges you require access to
data, because the charges depends on the customer and instrument and this
is information that is in several tables.

The one exception here is when you trade with bonds, because they may be
traded on interest rather than price, in which case the price has to be
computed from the interest. You also have to compute the accrued interest
for the bond, that the seller is to pay to the buyer. These computations
are not very simple to implement in SQL. What we do is that we call a
COM object that runs on the SQL Server machine that performs the
computation, so we still have this logic on the server.

Our customers have fairly modest volume of bond deals, so this is not an
issue. But assume that you have a site that trades exclusively in bonds,
and can perform many trades a second (not very likely, I think). In this
case, having the COM object on the server would take some toll that would
be bearable. We could make the COM object remote, but it would still be
one server. If instead the middle tier would get all trades to compute,
there could be several machines that each gets their load, so you can scale
better.

It's maybe not the best example, but I think it gives you the idea that
even if you put some logic in the middle tier, it may not be all logic,
but only some specific part.

Finally one more argument for having the logic in stored procedures: you
have all the code in one place. If you use the middle tier, you will jump
forth and back in different languages and the code is more difficult to
follow, debug and maintain.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp