ADO.NET - A Data Access Layer

  • Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/PNowa

  • Patrick,

    You wrote "we have to ensure that the SQL command passed to the procedure is actually a SELECT statement". I hope that you realize that the statement could be something like this:

    SELECT 1 DELETE _t_spsys_select_log WHERE log_id=(SELECT MAX(log_id) FROM _t_spsys_select_log)

    This means that we must trust the developer of the client application to give us a correct SELECT statement. This means that we trust that he only uses hard-coded strings or if he uses anything entered by the user, he validates them very well. If anyone wants to read further on this topic, see:

    http://www.nextgenss.com/papers/advanced_sql_injection.pdf

    Razvan

  • Razvan raises a good point, and one that reinforces the suggestion that a data layer is a good idea.  It's much easier to prevent SQL Injection and the like in a dedicated data layer, than on every individual SQL call.

    Tony

  • A few issues I see with this approach. I'm curious as to your opinion on them:

    1) It does nothing to prevent SQL injection attacks. I can pass in something like "select * from table ; delete * from table", which would qualify as a select statement, but would execute both the select and the delete statement. Very dangerous and hard to catch.

    2) Aren't you losing all the benefits of running stored procs by using sp_executesql? None of the queries are running against pre-compiled sprocs that way, and some queries can be very long and complex (much more than 1000 characters).

    Again, I really like the idea of a data access layer (it's been on our development list for a while now). I'm just not sure what the best approach is for it. I prefer to require the client to access all data through stored procedures (we develop a web based app), which makes it hard to develop a generic interface.

    Just my $0.02. I'm curious to hear what other people think.

    Greg Walker

    DBA

    ExpenseWatch.com


    Greg Walker
    DBA, ExpenseWatch.com

  • havent read the whole article, just wanted to let you know about the "Data Access Application Block" published by microsoft for that exact purpose, it is quite easy to use, details and downloads can be found here :

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daab-rm.asp

     

    cheers

    rugha


    -------------------------
    Oh no, I've done it again...
    -------------------------

  • The Data Access Application Block is really quite excellent. This is also another opportunity to plug Code Generation. I know, I know, I promised to write an article on the topic and I started one but it sucked I'll get back to work on it soon.

    My point is, you should not have to write 80% of the stored procedures or any of the data access layer. Let a code generator do the generic stuff for you. Check out CodeSmith at http://www.ericjsmith.net/codesmith/ or the Code Generation Network at http://www.codegeneration.net/.

    [font="Tahoma"]Bryant E. Byrd, BSSE MCDBA MCAD[/font]
    Business Intelligence Administrator
    MSBI Administration Blog

  • Hi all,

    My DAL starts with Stored Procedures and prepared commands and we use .NET framework components with corresponding typed datasets. Then you can drop your DAL Component and needed datasets to Win/WebForm and call its methods. It is good idea to create typed dataset properties in your component so it will allow you to select dataset instance using IDE property editor - cheers!

    Common DAL "framework" should be comprised of component base classes. That's how I see this problem. Btw, when you use SqlCommand object's parameters collection, "sql injection" is not a problem any more.

    Have a nice day

  • I agree with all Patryks reasons for using a data access layer.

    I also re-iterate rugha's comment - see the microsoft SqlHelper class which they publish separately as a freely downloadable Data Access Application Block.

    This allows the coder to use static methods to perform most data access tasks which makes things much easier. You can of course build on this to do logging etc...

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daab-rm.asp

  • Does DAL refuse Data-Binding approach? In other words can it be used when one wants a GUI control (as opposed to developer's SQL code) to take care about SELECT / UPDATE / INSERT / DELETE?

    I am having problems with an old application relying heavily on data binding. It needs to migrate to .NET. The database gradually became pretty ugly during its many-years lifetime.

    I'd love to create / use a DAL approach which seems to be the only way to maintain the application's being up and running while "remodeling" is being in progress. But...

    What about the first question in this post please?

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply