Click here to Skip to main content
15,886,137 members
Articles
(untagged)

Database Programming Rant

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
9 Aug 2010Apache2 min read 11.7K   2   1
Database programming rant

After a long while, I am back to dealing with databases directly from ADO.NET. Guys, this is ridiculous. Any serious library designed like that would be heckled. This is what I found (or rediscovered) in the course of one day:

  • If your SqlConnection uses SQL Server local transaction, you must manually transfer the transaction to the SqlCommands you use. If you don’t, you get InvalidOperationException.

    ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.

    You are on your own in determining what transaction that is: SqlConnection has this information, but it won't tell you. More details here.

  • If you have a typed DataSet with a number of tables connected by relationship, there is no easy way to fill it from the database all at once. E.g. if I have customers and orders, there is no way to get "all orders for customers with State='OK'" into the dataset. If you write a JOIN query, it will create one table, and the dataset won't convert it into multiple tables. You can use OleDB proprietary SHAPE queries, but
    • this is not standard SQL, and
    • you get some weird table names, so I could not make it to work as well

      So, you can build a relational structure in memory, but you cannot copy data from DB. The best you can do is filling the tables one by one. Ridiculous.

  • SqlDataAdapter won't automatically initialize insert, update, and delete commands when given the SELECT command. You must use SqlCommandBuilder object, which implicitly modifies the underlying adapter. Looks very weird.

    If their point was separation of concerns, then why the command builder cannot do it without the data adapter? Just take command text and return SqlCommand. More often than not, I do want the commands built if that's possible. I would either have the adapter build the commands by default (which can be turned off if not desired), or at least have some adapter factory object.

  • If you use SqlDataAdapter to add new rows with identity columns, there is no way to get resulting identity values back. The only thing I found short of writing SQL by hand is to build the insert command, steal its text, append something like "; SELECT SCOPE_IDENTITY();" to it, and then execute it by hand, bypassing the adapter.

    Bottom line: Ouch. So much time spent on problems that simply should not be there in a decently designed system.

This article was originally posted at http://www.ikriv.com/blog?p=526

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Technical Lead Thomson Reuters
United States United States
Ivan is a hands-on software architect/technical lead working for Thomson Reuters in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.

Please visit my web site: www.ikriv.com.

Comments and Discussions

 
QuestionGood criticism, so what? Pin
Thornik10-Aug-10 10:23
Thornik10-Aug-10 10:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.