Hello!
I have a question that is not realy only C# but I didn't find any better
group...
What is the most common/best way to handle sql queries in C#
1) Should I use stored procedures ? I like them because I have all my
queries in one place, easy to find and update... But I dont like them
because you never know where they are used from. If you change one it might
affect some area of the application you didn't think about. Ofcourse you get
the speed advantage but I'd be happy to give that up for a better design.
2) Should I declare the sql query localy in the method that wants to execute
it ? This is the most appealing method to me. This way I know exactly what
scope the query can be executed in. I can safetly modify the query and know
other parts of the application will not be affected.
3) I saw some other method to declare the queries as static class members.
To me it seems like a mixture of the above 2. The scope for the queries are
well defined (similar to 2), but it might be huge . You can have your
queries in a region in the class that is easy to find and update (similar to
1).
There are probably as many methods to use as there are developers... but
please give me comments, what do you perfer and why ? 4 3685
Hi Mikael, 1) Should I use stored procedures ? I like them because I have all my queries in one place, easy to find and update... But I dont like them because you never know where they are used from. If you change one it
might affect some area of the application you didn't think about. Ofcourse you
get the speed advantage but I'd be happy to give that up for a better design.
IMHO the SP are the best place to put the queries, if you need to change a
SP to return some other things, well then just create a new SP and call it
from whre you need it.
2) Should I declare the sql query localy in the method that wants to
execute it ? This is the most appealing method to me. This way I know exactly what scope the query can be executed in. I can safetly modify the query and
know other parts of the application will not be affected.
this is the WORST method , in case you change the DB you have queries all
over the system or systems , very bad design IMO. as I said before use SP
when ever you can
Hope this help,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Don't you find it hard to keep order of things with SP's ? The project I'm
working on now have over 1000 queries (at least) Just to come up with good
names for all of them is brainkilling.
"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> skrev i meddelandet
news:uL*************@tk2msftngp13.phx.gbl... Hi Mikael, 1) Should I use stored procedures ? I like them because I have all my queries in one place, easy to find and update... But I dont like them because you never know where they are used from. If you change one it might affect some area of the application you didn't think about. Ofcourse you get the speed advantage but I'd be happy to give that up for a better
design. IMHO the SP are the best place to put the queries, if you need to change
a SP to return some other things, well then just create a new SP and call it from whre you need it.
2) Should I declare the sql query localy in the method that wants to execute it ? This is the most appealing method to me. This way I know exactly
what scope the query can be executed in. I can safetly modify the query and know other parts of the application will not be affected.
this is the WORST method , in case you change the DB you have queries all over the system or systems , very bad design IMO. as I said before use SP when ever you can
Hope this help,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
Hello Ignacio !
Thanks for your feedback, its very appreciated =)
In all the systems I have build all the queries are most often used only
once (otherwise you should have a look at your database layer design).
Ofcourse some of them are used more than once but I would say thats just a
small procentage of the queries, and since you dont know which queries are
used more than once you get the problem I wrote about earlier.
I know it was tough in the old ASP world to make a clean separation of
database layer, buisness layer and interface layer. But now with C# and .NET
its much easier (I think anyway). So I was just wondering if .NET developers
still use SP's. And why ? I dont buy the argument that SP's is a good
abstraction layer to the DB. In my world that's the job for the database
layer.
"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> skrev i meddelandet
news:Op**************@TK2MSFTNGP12.phx.gbl... Hi Mikael,
Ok, then imagine for one moment that many queries used let's say two
times each , now if the DB change you may have to track !!! and change all those queries, recompile the system and finally and most important, test it. The horizon get darker if you have more than one system accessing the
same DB. The sp works as the abstraction layer between the application and the physical structure of the data. your application should be abstracted of
how the data is keeped.
I would like to hear the opinion of others but I always use SP , I
haven't used queries in my code since my first steps in ASP.
Hope this help,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Mikael Janers" <NO************@home.se__SPAMFILTER> wrote in message news:OT**************@TK2MSFTNGP12.phx.gbl... Don't you find it hard to keep order of things with SP's ? The project
I'm working on now have over 1000 queries (at least) Just to come up with
good names for all of them is brainkilling.
"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> skrev i meddelandet news:uL*************@tk2msftngp13.phx.gbl... Hi Mikael, > 1) Should I use stored procedures ? I like them because I have all
my > queries in one place, easy to find and update... But I dont like
them > because you never know where they are used from. If you change one
it might > affect some area of the application you didn't think about. Ofcourse you get > the speed advantage but I'd be happy to give that up for a better design. IMHO the SP are the best place to put the queries, if you need to change a SP to return some other things, well then just create a new SP and
call it from whre you need it.
> 2) Should I declare the sql query localy in the method that wants to execute > it ? This is the most appealing method to me. This way I know
exactly what > scope the query can be executed in. I can safetly modify the query
and know > other parts of the application will not be affected.
this is the WORST method , in case you change the DB you have queries all over the system or systems , very bad design IMO. as I said before use SP when ever you can
Hope this help,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
Hello Ignacio !
Thanks for your feedback, its very appreciated =)
In all the systems I have build all the queries are most often used only
once (otherwise you should have a look at your database layer design).
Ofcourse some of them are used more than once but I would say thats just a
small procentage of the queries, and since you dont know which queries are
used more than once you get the problem I wrote about earlier.
I know it was tough in the old ASP world to make a clean separation of
database layer, buisness layer and interface layer. But now with C# and .NET
its much easier (I think anyway). So I was just wondering if .NET developers
still use SP's. And why ? I dont buy the argument that SP's is a good
abstraction layer to the DB. In my world that's the job for the database
layer.
"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> skrev i meddelandet
news:Op**************@TK2MSFTNGP12.phx.gbl... Hi Mikael,
Ok, then imagine for one moment that many queries used let's say two
times each , now if the DB change you may have to track !!! and change all those queries, recompile the system and finally and most important, test it. The horizon get darker if you have more than one system accessing the
same DB. The sp works as the abstraction layer between the application and the physical structure of the data. your application should be abstracted of
how the data is keeped.
I would like to hear the opinion of others but I always use SP , I
haven't used queries in my code since my first steps in ASP.
Hope this help,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Mikael Janers" <NO************@home.se__SPAMFILTER> wrote in message news:OT**************@TK2MSFTNGP12.phx.gbl... Don't you find it hard to keep order of things with SP's ? The project
I'm working on now have over 1000 queries (at least) Just to come up with
good names for all of them is brainkilling.
"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> skrev i meddelandet news:uL*************@tk2msftngp13.phx.gbl... Hi Mikael, > 1) Should I use stored procedures ? I like them because I have all
my > queries in one place, easy to find and update... But I dont like
them > because you never know where they are used from. If you change one
it might > affect some area of the application you didn't think about. Ofcourse you get > the speed advantage but I'd be happy to give that up for a better design. IMHO the SP are the best place to put the queries, if you need to change a SP to return some other things, well then just create a new SP and
call it from whre you need it.
> 2) Should I declare the sql query localy in the method that wants to execute > it ? This is the most appealing method to me. This way I know
exactly what > scope the query can be executed in. I can safetly modify the query
and know > other parts of the application will not be affected.
this is the WORST method , in case you change the DB you have queries all over the system or systems , very bad design IMO. as I said before use SP when ever you can
Hope this help,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Zambo via SQLMonster.com |
last post by:
Hi!
We have Sql Server 2000 in our server (NT 4). Our database have now about
+350.000 rows with information of images. Table have lot of columns
including information about image name, keywords,...
|
by: (Pete Cresswell) |
last post by:
Seems like creating a #temp table is kind of useless because it cannot be bound
to a subform.
OTOH, seems like a waste of resources to populate work tables in the "real"
database - both because...
|
by: Abhi |
last post by:
FYI:
This message is for the benefit of MS Access Community. I found that
this prblem has been encounterd by many but there is hardly any place
where a complete solution is posted. So I thought...
|
by: XML newbie: Urgent pls help! |
last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it
verifies the login information it should display the SessionID and enable
some button . I appreciate your help and thanku...
|
by: PeteCresswell |
last post by:
When writing to a work DB under C:\Documents and
Settings\...., what is the best way to handle MakeTable
queries?
The only approaches I can think of are:...
| |
by: rich |
last post by:
I am building an app using php and postgresql. My questionis this.
How do you handle people wanting to make parallel changes to a record.
Since in web apps you are doing a select, bring over a...
|
by: Sanny |
last post by:
I am using a MySql database for chat application.
Every 3 seconds the database is searched for various details.
I would like to know How many individual can it handle at a time.
Say there...
|
by: swep |
last post by:
To any who might be able to help this is the situation.I have a
dropdown list that gets populated from SQL. It contains both single and
double quotes. It populates the dropdown list just fine. I...
|
by: Ming |
last post by:
For example, 100,000 records, each record has 10 fields and may belong
to one or more categories. How shall I save those records in DB? I
think it is a very typical concern for most online shopping...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |