Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. No more stored procedures

No more stored procedures

Scheduled Pinned Locked Moved The Lounge
databasecsharpsql-servercomsysadmin
152 Posts 63 Posters 15 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Member 96

    Rama Krishna Vavilala wrote:

    I think that is a way too general statement. It's like saying that no othe language should be used except C++.

    Yeah it's hyperbole I agree, I just wanted to get the juices flowing in this discussion! ;)

    Rama Krishna Vavilala wrote:

    I beg to differ. I did my own benchmarks and in many complex queries SPs performed a lot better than plain SQL through code. Talk about a difference of 6 hrs and 15 minutes in one case.

    Woops! That's not something I would be willing to admit, there is no difference other than compilation time and the quality of the query written in the first place.

    R Offline
    R Offline
    Rama Krishna Vavilala
    wrote on last edited by
    #53

    John Cardinal wrote:

    there is no difference other than compilation time and the quality of the query written in the first place.

    There is a third thing: data transfer from the DBMS process to the actual client process and converting them to language specific data types such as variants. In the case I am referring there were two million records which have to be all scanned due to some business requirements.


    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

    M 1 Reply Last reply
    0
    • M Member 96

      Christian Graus wrote:

      So, you're saying that 20 lines of SQL generate as much network traffic as a proc name ?

      :rolleyes: So what? If it means more features for end users, easier to maintain code and easier to support application?

      Christian Graus wrote:

      and the people who had access understood that their warranty expired if they changed code themselves.

      Again... :rolleyes: My experience is with thousands of users all over the globe that get free support from us, slightly different perhaps.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #54

      John Cardinal wrote:

      So what?

      So, I made the point, you disputed it, now you're backing down ?

      John Cardinal wrote:

      If it means more features for end users

      It can't possibly mean that

      John Cardinal wrote:

      easier to maintain code

      It absolutely cannot mean that, it opens the door to hideous to maintain code, although it doesn't guarentee it, and I doubt it's the case in your apps

      John Cardinal wrote:

      easier to support application

      Only in the sense that you seem to be selling to morons and you let them walk all over you.

      John Cardinal wrote:

      My experience is with thousands of users all over the globe that get free support from us, slightly different perhaps.

      It's true that the apps I've deployed have been local ( at least, the ones that use SQL Server, I have users all over the world with an app that doesn't use SQL ). But, I don't see how that changes the basic principle that most users should not have access to the SQL Server, and the people that do, should know that they lose their warranty if they change it. If you go in and fix a problem due to people changing procs, it gets charged at a premium rate. Do that once, and their management will make sure it doesn't happen again.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      M 1 Reply Last reply
      0
      • M Miszou

        I've just recieved an email from my supervisor, asking me not to use any server-side functions, stored procedures, views or queries and to keep all database coding within the code itself - just in case we need to change databases or sell to a client that doesn't use the same database that we do. We write in-house web apps (classic ASP and C#) using SQL Server 2000 and have so far sold a total of zero applications to third parties (We are not a software house - just a small IT department serving the rest of the company). Pseudo-code for the offending stored procedure that prompted the new policy is shown below: begin insert data into table select scope_identity() as userid end I was instructed to change it to two separate calls from within the code: recordset.open( "insert data into table" ) ... recordset.open( "select @@identity" ) Any thoughts? I have mine, but I'd be interested in hearing from others...


        The StartPage Randomizer | The Timelapse Project | A Random Web Page

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #55

        Miszou wrote:

        Any thoughts?

        Does your boss have pointy hair?

        the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
        Deja View - the feeling that you've seen this post before.

        1 Reply Last reply
        0
        • D David Stone

          That's the dumbest thing I've ever heard.


          CodeProject: 'I mean where else would you rather be pissed off?' - Jeremy Falcon

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #56

          David Stone wrote:

          That's the dumbest thing I've ever heard.

          I agree.


          "That's no moon, it's a space station." - Obi-wan Kenobi

          1 Reply Last reply
          0
          • M Miszou

            I've just recieved an email from my supervisor, asking me not to use any server-side functions, stored procedures, views or queries and to keep all database coding within the code itself - just in case we need to change databases or sell to a client that doesn't use the same database that we do. We write in-house web apps (classic ASP and C#) using SQL Server 2000 and have so far sold a total of zero applications to third parties (We are not a software house - just a small IT department serving the rest of the company). Pseudo-code for the offending stored procedure that prompted the new policy is shown below: begin insert data into table select scope_identity() as userid end I was instructed to change it to two separate calls from within the code: recordset.open( "insert data into table" ) ... recordset.open( "select @@identity" ) Any thoughts? I have mine, but I'd be interested in hearing from others...


            The StartPage Randomizer | The Timelapse Project | A Random Web Page

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #57

            Miszou wrote:

            Any thoughts? I have mine, but I'd be interested in hearing from others...

            Run away!!!


            Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

            A 1 Reply Last reply
            0
            • R Rama Krishna Vavilala

              John Cardinal wrote:

              there is no difference other than compilation time and the quality of the query written in the first place.

              There is a third thing: data transfer from the DBMS process to the actual client process and converting them to language specific data types such as variants. In the case I am referring there were two million records which have to be all scanned due to some business requirements.


              Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

              M Offline
              M Offline
              Member 96
              wrote on last edited by
              #58

              Rama Krishna Vavilala wrote:

              variants

              There's your problem right there you were using VB weren't you? ;P

              1 Reply Last reply
              0
              • R Rama Krishna Vavilala

                Rob Graham wrote:

                That is likely to be broken from the start in any multiuser environment.

                Not true: From docs: @@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session.


                Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

                C Offline
                C Offline
                cmk
                wrote on last edited by
                #59

                Rama Krishna Vavilala wrote:

                Not true: From docs: @@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session.

                recordset.open( "insert data into table" ) ... recordset.open( "select @@identity" ) As long as the first open() doesn't close the connection after executing its statement, or the second open() doesn't close/open a new connection before executing its statement, then the current session may be equal to current connection. Even then you would have to use SCOPE_IDENTITY() not @@identity (the insert may fire a trigger which executes another insert - different scope). I believe few are willing to take the chance on this (session == connection) always being true across all RDBMS', let alone that their recordset class maintains a connection behind the scenes.

                ...cmk Save the whales - collect the whole set

                R 1 Reply Last reply
                0
                • M Member 96

                  Stored procedures should never be used in a commercial software application. 1) Performance is not noticeably better to the end user. That used to be true a very long time ago supposedly, I don't know from personal experience because I wasn't databasing in the 70s and 80's. I can testify without a shadow of a doubt that it is no longer true for FireBird, MS SQL server or Oracle. I had a major app that was targetted exclusively at MS SQL server, about halfway through development we came to our senses and decided to target different databases, I personally have benchmarks and a lot of experience converting the app to DAL and there is no question that the end user will never see a difference in peformance either way. 2) All data access should be done through a data access layer in a properly stratified design, i.e. presentation layer, business object layer, data access layer (and usually more in between). This gurantees portability, forcing your end user into a particular database brand when it's easy to write an independant DAL for different DB's is just stupid. 3) There are many *many* things you can not do with stored procedures that you can easily do in code. 4) There is little or nothing you can do to protect your intellectual property when it's in plain sight in the database in stored procedures. 5) There is no security issue with using dynamic sql as long as you know what you are doing. I agree completely with your boss on the first part, on the second part about inserting a record adn retreiving it's unique id that's completely wrong for dynamic sql, instead generate the ID's at the application and insert the record in one trip. We use Guid's for that exactly to avoid the whole server generated identity trap.

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #60

                  John Cardinal wrote:

                  There is little or nothing you can do to protect your intellectual property when it's in plain sight in the database in stored procedures

                  If you read the entry for CREATE PROCEDURE[^] you will see that one of the options is to encrypt it.


                  Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                  M 1 Reply Last reply
                  0
                  • C Christian Graus

                    John Cardinal wrote:

                    So what?

                    So, I made the point, you disputed it, now you're backing down ?

                    John Cardinal wrote:

                    If it means more features for end users

                    It can't possibly mean that

                    John Cardinal wrote:

                    easier to maintain code

                    It absolutely cannot mean that, it opens the door to hideous to maintain code, although it doesn't guarentee it, and I doubt it's the case in your apps

                    John Cardinal wrote:

                    easier to support application

                    Only in the sense that you seem to be selling to morons and you let them walk all over you.

                    John Cardinal wrote:

                    My experience is with thousands of users all over the globe that get free support from us, slightly different perhaps.

                    It's true that the apps I've deployed have been local ( at least, the ones that use SQL Server, I have users all over the world with an app that doesn't use SQL ). But, I don't see how that changes the basic principle that most users should not have access to the SQL Server, and the people that do, should know that they lose their warranty if they change it. If you go in and fix a problem due to people changing procs, it gets charged at a premium rate. Do that once, and their management will make sure it doesn't happen again.

                    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                    M Offline
                    M Offline
                    Member 96
                    wrote on last edited by
                    #61

                    I'll concede that dynamic sql could in some cases result in more traffic outgoing to the db server, considering the ratio of outgoing to incoming data I'm also sure you are willing to concede that this is pretty much irrelevant in the 21st century that most of us are working in now. ;)

                    Christian Graus wrote:

                    But, I don't see how that changes the basic principle that most users should not have access to the SQL Server,

                    Well they shouldn't and you're right we're under no obligation to fix it if they break it...technically...but if you have thousands of users and even a small percentage do this then it's worthwhile avoiding the potential for the problem in the first place. Even if it's a case where you charge them to fix it, the time spent just figuring out that the problem is a result of someone changing something and the effort required just to prove that to their boss against their employees denials is something else again. You seem to take things very literally and down to the millisecond where I'm speaking more in generalitites here. Of course a stored procedure with a pre-compiled execution plan run once will be technically faster than the dynamic sql with no cached execution plan, but the differences are so miniscule in reality that if there is even one more feature you can add to the program that is populare and useful but requires dynamic sql then you'd be crazy not to use it. In this day and age people want choices, choices of database platform is a big one and you can never go out of business giving the customers what they want.

                    1 Reply Last reply
                    0
                    • M Member 96

                      James R. Twine wrote:

                      Not really - we have had little utilities like strings for quite some time now. If you have enough permissions to launch the application, you have enough to dump the binary into an editor and/or get the strings out of it. Unless you encode the strings in some manner, they are in the binary in plaintext.

                      I can't tell you the number of clients over the years that have messed with databases that we include with our software. They see it, have a little experience and want to mess with it. Stored procedures are easily messed with by end users, dynamic sql isn't. The number one security threat for commercial software developers is protecting users from themselves, external threats are a distant second.

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #62

                      John Cardinal wrote:

                      Stored procedures are easily messed with by end users, dynamic sql isn't.

                      You can always fire up the Query Analyser and mess with it instead. :rolleyes:


                      Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                      M 1 Reply Last reply
                      0
                      • C Colin Angus Mackay

                        John Cardinal wrote:

                        There is little or nothing you can do to protect your intellectual property when it's in plain sight in the database in stored procedures

                        If you read the entry for CREATE PROCEDURE[^] you will see that one of the options is to encrypt it.


                        Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                        M Offline
                        M Offline
                        Member 96
                        wrote on last edited by
                        #63

                        Sadly that's much less protection than simply using dynamic sql with an obfuscated and string encrypted application, there are numerous well publicized ways of decrypting sp's.

                        G 1 Reply Last reply
                        0
                        • M Member 96

                          Christian Graus wrote:

                          I guess that depends. How can you claim that it never is when 1 - stored procs are precompiled 2- stored procs lower the amount of network traffic required to make a request

                          I said *noticeably* different. If we forget entirely and conveinently the fact that execution plans are cached on most database servers now regardless of whether they came from dynamic sql or sp, we're talking maybe 10 seconds total over the entire course of day. Stored procedures do *not* reduce network traffice, well designed queries do.

                          Christian Graus wrote:

                          How is this possible, when a stored proc is just a bunch of SQL

                          Because you can write the sql dynamically in your code as your application is running, there are many areas you can take advantage of this when you are not fettered by set in stone stored procedures, I use it for filtering and sorting in a 3rd party datagrid that has complex filtering built into it that isn't sql friendly, I use it for very performant knowledgebase type searching, complex reporting.

                          Christian Graus wrote:

                          John Cardinal wrote: There is little or nothing you can do to protect your intellectual property when it's in plain sight in the database in stored procedures. If you're writing a C++ app, this is true. Assuming someone has access to your SQL Server, they can see your SQL.

                          Well my primary concern here is that I don't want my well meaning end users to go messing about with the stored procedures which they will do on their own given an easy opportunity to do so, but secondarily since my logic is primarily in my source code and it's obfuscated it's harder to get at that in the end which is all we can really do.

                          C Offline
                          C Offline
                          Colin Angus Mackay
                          wrote on last edited by
                          #64

                          John Cardinal wrote:

                          Stored procedures do *not* reduce network traffice, well designed queries do.

                          And having a query manipulate data inside a stored procedure then send back the final answer is much better than having lots of data being sent back-and-forth across the network so some client app can do what could be done in a stored procedure.


                          Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                          M 1 Reply Last reply
                          0
                          • C Colin Angus Mackay

                            John Cardinal wrote:

                            Stored procedures are easily messed with by end users, dynamic sql isn't.

                            You can always fire up the Query Analyser and mess with it instead. :rolleyes:


                            Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                            M Offline
                            M Offline
                            Member 96
                            wrote on last edited by
                            #65

                            You can do anything if you know enough, as long as people can't modify my queries, break the program and then come for my support to fix it I don't care what they do.

                            C 1 Reply Last reply
                            0
                            • M Member 96

                              Christian Graus wrote:

                              So, you're saying that 20 lines of SQL generate as much network traffic as a proc name ?

                              :rolleyes: So what? If it means more features for end users, easier to maintain code and easier to support application?

                              Christian Graus wrote:

                              and the people who had access understood that their warranty expired if they changed code themselves.

                              Again... :rolleyes: My experience is with thousands of users all over the globe that get free support from us, slightly different perhaps.

                              C Offline
                              C Offline
                              Colin Angus Mackay
                              wrote on last edited by
                              #66

                              John Cardinal wrote:

                              If it means more features for end users, easier to maintain code and easier to support application?

                              The one and only time I worked on a project that relied on dynamic SQL it turned out to be the most difficult, unreadable, unmaintainable pile of festering crap I ever had the misfortune to have to work with.


                              Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                              1 Reply Last reply
                              0
                              • C Christian Graus

                                Your business model is flawed. I never charge for support, either. But, support ends when people mess with the program, simple as that. Can I pull my car to pieces, then call for warranty support because it's broken ? No.

                                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                                C Offline
                                C Offline
                                Colin Angus Mackay
                                wrote on last edited by
                                #67

                                Christian Graus wrote:

                                Can I pull my car to pieces, then call for warranty support because it's broken ? No.

                                That is an excellent analogy - I'll have to remember that.


                                Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                                1 Reply Last reply
                                0
                                • M Member 96

                                  You can do anything if you know enough, as long as people can't modify my queries, break the program and then come for my support to fix it I don't care what they do.

                                  C Offline
                                  C Offline
                                  Colin Angus Mackay
                                  wrote on last edited by
                                  #68

                                  John Cardinal wrote:

                                  as long as people can't modify my queries, break the program and then come for my support to fix it I don't care what they do.

                                  Okay - so they go in to query analyzer and mess with the data structure and your application fails. Might as well have used stored procedures because its just as messy.


                                  Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                                  1 Reply Last reply
                                  0
                                  • M Member 96

                                    Rama Krishna Vavilala wrote:

                                    I think that is a way too general statement. It's like saying that no othe language should be used except C++.

                                    Yeah it's hyperbole I agree, I just wanted to get the juices flowing in this discussion! ;)

                                    Rama Krishna Vavilala wrote:

                                    I beg to differ. I did my own benchmarks and in many complex queries SPs performed a lot better than plain SQL through code. Talk about a difference of 6 hrs and 15 minutes in one case.

                                    Woops! That's not something I would be willing to admit, there is no difference other than compilation time and the quality of the query written in the first place.

                                    C Offline
                                    C Offline
                                    Colin Angus Mackay
                                    wrote on last edited by
                                    #69

                                    John Cardinal wrote:

                                    Woops! That's not something I would be willing to admit

                                    Why not? I think it is great to be able to say I made a mistake and I fixed it and this was the result. It shows willingness to learn.


                                    Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                                    1 Reply Last reply
                                    0
                                    • M Member 96

                                      James R. Twine wrote:

                                      There is no reason for saying flat out that all SPs suck and should be avoided.

                                      I disagree...it leads to a hopefully, enlightening discussion! ;)

                                      J Offline
                                      J Offline
                                      James R Twine
                                      wrote on last edited by
                                      #70

                                      Touche!

                                      -=- James


                                      If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                                      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                                      DeleteFXPFiles & CheckFavorites (Please rate this post!)

                                      1 Reply Last reply
                                      0
                                      • C cmk

                                        Rama Krishna Vavilala wrote:

                                        Not true: From docs: @@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session.

                                        recordset.open( "insert data into table" ) ... recordset.open( "select @@identity" ) As long as the first open() doesn't close the connection after executing its statement, or the second open() doesn't close/open a new connection before executing its statement, then the current session may be equal to current connection. Even then you would have to use SCOPE_IDENTITY() not @@identity (the insert may fire a trigger which executes another insert - different scope). I believe few are willing to take the chance on this (session == connection) always being true across all RDBMS', let alone that their recordset class maintains a connection behind the scenes.

                                        ...cmk Save the whales - collect the whole set

                                        R Offline
                                        R Offline
                                        Rama Krishna Vavilala
                                        wrote on last edited by
                                        #71

                                        Yes, I agree with you if you want to go into that level of detail.:)


                                        Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

                                        1 Reply Last reply
                                        0
                                        • M Member 96

                                          Stored procedures should never be used in a commercial software application. 1) Performance is not noticeably better to the end user. That used to be true a very long time ago supposedly, I don't know from personal experience because I wasn't databasing in the 70s and 80's. I can testify without a shadow of a doubt that it is no longer true for FireBird, MS SQL server or Oracle. I had a major app that was targetted exclusively at MS SQL server, about halfway through development we came to our senses and decided to target different databases, I personally have benchmarks and a lot of experience converting the app to DAL and there is no question that the end user will never see a difference in peformance either way. 2) All data access should be done through a data access layer in a properly stratified design, i.e. presentation layer, business object layer, data access layer (and usually more in between). This gurantees portability, forcing your end user into a particular database brand when it's easy to write an independant DAL for different DB's is just stupid. 3) There are many *many* things you can not do with stored procedures that you can easily do in code. 4) There is little or nothing you can do to protect your intellectual property when it's in plain sight in the database in stored procedures. 5) There is no security issue with using dynamic sql as long as you know what you are doing. I agree completely with your boss on the first part, on the second part about inserting a record adn retreiving it's unique id that's completely wrong for dynamic sql, instead generate the ID's at the application and insert the record in one trip. We use Guid's for that exactly to avoid the whole server generated identity trap.

                                          R Offline
                                          R Offline
                                          Rocky Moore
                                          wrote on last edited by
                                          #72
                                          1. Already beat to death in other replies 2) At minimum, better to have a provider type system if you wish to work with multiple database venders so that you can optimize for each as time permits or usage demands. Additionally, now that we have CLR on the server, it opens up even more doors for optimizing and features. Just a few simple things such as being able to access RegEx server side it pretty handy! 3) Silly... 4) You cannot protect them anyway if you the end user has access to the Server. Anyway can run a profiler on the the transactions and monitor anything going to or from the server. The end result is that you have to distribute new versions of your application every time you have to make a small change to any query. I cannot begin to say how many times a simple tweak to a SP fixed problems or improved performance without all the hassle of producing yet another version of the client applications. SP have become popular, not because someone said to use them, they save time and money when you use them properly and you make sure the server is locked.

                                          Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: USA City Burnt To Death...

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups