CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

John Papa [MVP C#]

.NET Code Samples, Data Access, and Other Musings

May 2005 - Posts

  • Clarifying ADO.NET 2 Batch Updates

    Pablo Castro, Microsoft's Program Manager of the ADO.NET Team, has a good post last week that helps clarify how bath updates are intended to work in ADO.NET 2. This is a common discussion that I am drawn into since the DataAdapter actually invokes its command for each modified row in the DataTable that it is associated with. Thus if you have a DataTable with the following deltas:

    • 7 modified rows
    • 2 added rows
    • 2 deleted rows

    The DataAdapter will invoke the UpdateCommand 7 times, the InsertCommand 2 times and the DeleteCommand 2 times for a total of 11 round trips. There are several ways to work around this, some of which Pablo points out such as sending all of the SQL statements down at once manually. You can also use diffgrams using SQL Server's XML features, too. But none of the solutions is as elegant as how ADO.NET shoulda, coulda , woulda handled it. Kudos to Pablo for a good explanation!

    Posted May 26 2005, 05:18 AM by John Papa with 2 comment(s)
    Filed under: ,
  • Review: Follow-Up Notes on ReSharper and .NET Refactor

    As I mentioned in a blog last week, I downloaded two refactoring tools: .NET Refactor and ReSharper. I had some really horrible experiences with refactoring tools in the past, so I was a bit skeptical going in. It has been a week so here are a few more thoughts about the tools.

    While .NET Refactor has some nice features, like the how it can move code into regions for you and how it creates a list of regions you can choose form, I found that it just did not have enough features to really make me want or need to use it. In fact, I have uninstalled it already.

    ReSharper has a much more robust feature set and for the first time ever, I am glad that a tool prompts me with occasional tips. I did not know any of the shortcuts that it offers, so the tips have been nice since I did not read the help file. I especially love the Find Usages feature. I click on a variable and it finds every place that it is used. This past week I was tasked with renaming a class. I used ReSharper's Find Usages feature to find all locations that it was used before I went ahead with the refactoring. It was smart enough to find out that it implemented an interface and it asked me if I wanted to find usages of the interface too. Very helpful, indeed! It sure is nice to see where something is used before making a refactoring decision. Measure twice, cut once. I then asked it to rename the class and it went and did so everywhere it was referenced. Since this was used in 7 projects across a solution, this was nice time saver. I especially like how ReSharper analyzes and highlights my code files in places where I have invalid references, redundant “using” statements, and methods which are not called by anything. This tool has saved me a lot of time and pro-actively prevented bugs.

    Sounds like a winner so far, huh? I think so. To be fair, it does have some issues, too. My biggest issues with ReSharper so far are how long it takes to load and how much precious RAM it consumes. I loaded my project without ReSharper in about 20 seconds (24 projects in the solution with a ton if references). When I load the project with ReSharper it takes over 90 seconds to load while at analyzes the project and loads its cache. The good side of this is that it is relatively quick to use once it is loaded. But still, taking 90 to 150 seconds to load is a bit of a pain, especially when I open and close project files throughout the day. I also told the tool to show how much memory it consumes. This fluctuates, of course, depending on what I am doing. But it seems to float between 70MB and 130MB of RAM. I have 1GB of RAM which is getting to be tight these days, so this is just something to be aware of. Not a problem, just something to understand if you run with low RAM.

    So far I am very pleased with ReSharper and I might just add it to my collection of tools. AT $149, its enough for me to pause but if it continues to be as useful as I have found it thus far, it could pay for itself. I’ve got a few weeks left on my 30 day trial …

     

     

    Posted May 20 2005, 02:37 PM by John Papa with 6 comment(s)
    Filed under:
  • Review of Dual Monitor Software

    OK, so it has taken me a long time to give in and join the growing group of developers who use 2 or more monitors. Some of my colleagues have been using them for years and touting the incredible convenience that it is to have 2 monitors. I don’t really have a good reason why I never did it other than the cost of the second monitor. Now that most video cards support dual monitors and the price of LCD panels has come down considerably, I decided to go for it. So I am late to the party. Now I keep my Visual Studio.NET code window up on 1 monitor and the properties, toolbox, task list, solution explorer, and other windows in the second monitor. It really is a huge convenience as I was always fighting for more real estate on my screen for my code windows.

    But once you go to dual monitors, you start to notice some things that would really be great features to have. For example, when I switched I noticed that the Windows task bar was only on my primary monitor. I wanted it to be on the second monitor, as well so I could see what minimized windows were on which monitor. Also, to move a maximized window from one monitor to the other monitor I had to un-maximize it, drag it to the other monitor and then re-maximize it. Just a little inconvenient. Then I had some “wants” like having 2 different screen savers and 2 different desktop wallpapers (1 for each monitor). So I went looking for some of the dual monitor software offerings on the web. I found several and I won’t review all of them, but I will review what I felt were good choices in both the free and non-free categories.

    Multi-Mon

    First for the free tool, I downloaded and installed Oscar’s Multi-Monitor task bar. I found this at the MediaChance web site which also offers other applications. One really nice feature is that Multi-Mon will expand the desktop across 3 monitors. Pretty cool if you have 3. Its taken me this long to use 2 (read $$$)and my desk would just be covered if I went to 3, so I did not try this feature. But its nice to know that it supports it. The web site also discusses how you can use 2 video cards to set up a triple monitor setup. Anyway, back to the reason I downloaded it … having the task bar on both monitors. Download was quick, installation was easy, and it worked flawlessly in my trials. It puts a button at the upper right of your windows’ title bar that lets you move the window to the other monitor with a single click.

    The Multi-Mon task bar is gray, like the old Windows 2000 task bar. I did not see a setting to make it look like the Windows XP task bar. It also has a feature called the ClipBoard Extender which traps items that you saved to the clipboard. I wasn’t much for the feature other than that it also allows you to run application. For example, if you type calc in the Clipboard Extender and press the F5 key it will run the Windows Calculator application. Overall this tool worked well and since it is free, it isn’t a bad choice if you want something to extend your task bar across 2 or 3 monitors. However, it did not support having 2 different desktop wallpapers.

     

    UltraMon

    The best tool I have seen so far for extending the task bar across 2 or 3 monitors, supporting different screen savers, different desktop wallpapers is Realtime Soft UltraMon. This tool has a 30 day trial period and costs $39.95 for a single license. Again the download was quick and the installation was simple. The task bar loaded flawlessly and looks like the Windows XP blue task bar. It has several options that you can configure such as telling it which task bar to put the windows on. Just like Multi-Mon, it puts a button at the upper right of your windows’ title bar that lets you move the window to the other monitor with a single click.

     

    It also adds another button to the title bar of a window that lets you maximize the windows across both monitors. It also support having a different wallpaper on each monitor (so I get to stare at 2 different photos of my kids). AN it supports having different screen savers on each monitor. Overall, I liked UltraMon better as the few extra features were interesting to me. I will probably buy UltraMon as opposed to using the free Multi-Mon, although both worked well for the basic task bar extension.

    I reviewed a few different tools and these were the best in each free and costly categories that I found. If any of you know of a better tool, please pass it on to me.

  • Initial Thoughts on .NET Refactor and ReSharper

    In the past I have been skeptical of the refactoring tools purely because my experiences have been such that they are buggy, can slow down my IDE while they are processing and have even crashed my IDE at times. Well, its been a year or so since I have tried them so I figured I would give them another shot last week. After all, the idea behind refactoring tools is pretty awesome, if they work. Most of my code is in C#. There is a lot of development time and convenience to be gained from using them. (Yes, VS 2005 is going to have some refactoring built in, but that doesn't help my VS 2003 projects.)

    OK, so I downloaded .NET Refactor and its service update. Easy enough installation process too. The featureset is OK, but I found the region features to be a bit awkward. My list of saved regions would disappear at times and reset itself to a default list. Also, when I move code to a region, sometimes it throws an exception on me. I also tried the Refactor Strings feature and it threw an exception, too. I had more luck with renaming of variables feature and the Extract method features ... they seemed to work fine for me and were quite useful. Overall, I am mixed on the product so far.

    Next I downloaded ReSharper from JetBrains. Installation was just as easy but it takes a long time to load large projects now as ReSharper loads and sets up its caching. Once it is loaded it is fast, though. I'll have to play with it some more to see if this is enough of an annoyance to abandon it or not. It has some of the same and some different features than that of .NET Refactor. The one thing I noticed (or did not notice) is that none of the features I tried with ReSharper threw an exception. In fact, I have not seen any major issues thus far (crossing my fingers).  I like its color coding and highlighting of "warning" areas, they come in handy in locating unused code blocks. I also like how it implements an interface for me (nice code saving feature) I found this tool much simpler to use and much more effective in my initial trial than I have with .NET Refactor. Of course, it has only been a week, but so far I like what I see from ReSharper.

    I'll post more on these as I tackle more of their features.

     

     

  • C# Casting Quiz

    There are several ways to convert and cast values in .NET. For example, DirectCast versus System.Convert and if you are a VB.NET'er, you have the CInt, CBool, Cxxx functions. It is along these lines that I offer this quiz: What are the differences between the following ways to cast an object?

     

    Casting quiz
    /// Technique #1
    object item = GetIt();
    Dog dog = (Dog)item;
    
    /// Technique #2
    object item = GetIt();
    Dog dog = item as Dog;
    
    
    public object GetIt()
    {
        object x = null;
        /// Does something that tries to get an instance of an object
        ...
        ...
        ...
        return x;
    }
    

    What is the difference between these 2 techniques of casting and when would you want to use one over the other?
    Posted May 12 2005, 05:45 AM by John Papa with 12 comment(s)
    Filed under:
  • Exploring Enterprise Library's Data Access Applications Blocks

    The July 2005 issue of MSDN Magazine is now available online. The amount of discussion that has surrounded the Enterprise Library and its Application Blocks (good, bad and indifferent) has been tremendous. I decided to create a 3 part series that explores the Enterprise Library Data Access blocks in my Data Points column. In this issue I discuss how how the Enterprise Library DAAB fits into an architecture as well as some best practices in using the block. I review the Enterprise Library model and dive right into the DAAB and its configuration and cryptography features, when and where the DAAB can be used, and lots more.

    There is a lot to review with Ent Lib and only so much fits into an article, so I decided to split this up into a 3 parter. In the upcoming Part 2 and Part 3 I explore how post build events can be used to ease the use of configuration files, several ways of retrieving data, saving data, transactions with Ent Lib, using NUnit with Ent Lib, and its factory model.

     
  • Collections and Data Binding with Dino

    For a look at a non ADO.NET solution ... Dino Esposito wrote an article called Collections and Data Binding in a recent MSDN Magazine issue. Its a good read and addresses how to bind collections to controls, as opposed to using ADO.NET objects for binding. I believe he is going to follow this up with a discussion of collections vs DataSets in a future issue.

     

    Posted May 03 2005, 07:52 PM by John Papa with 1 comment(s)
    Filed under:
More Posts