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

April 2006 - Posts

  • Developing with SQL Server 2005 - XML Code Samples

    As promised here are the main code samples I demonstrated last week at the Toronto VSLive! conference for the Developing with SQL Server 2005 (XML Features) session. I will also post the code for the SQL Server 2005 and XML session here.

    Topics include:

    • XML Data Type
    • XML Schema Collections
    • FOR XML
    • Querying with XQuery
    • Modifying data with XQuery

    See the code in the zip file attachment below this post.

    Posted Apr 30 2006, 09:27 PM by John Papa with 1 comment(s)
    Filed under: ,
  • Developing with SQL Server 2005 - T-SQL Code Samples

    As promised here are the main code samples I demonstrated last week at the Toronto VSLive! conference for the Developing with SQL Server 2005 (T-SQL) session. I will also post the code for the SQL Server 2005 XML session here.

    Topics include:

    • Exception Handling
    • EventData
    • Triggers
    • Common Table Expressions
    • Views and Derived/Inline Tables
    • DRI Enhancements

    See the code in the zip file attachment below this post.

    Posted Apr 30 2006, 09:19 PM by John Papa with 3 comment(s)
    Filed under: ,
  • SQL Server 2005 XML Support, Exception Handling, DDL Triggers

    The May 2006 issue of MSDN Magazine is now posted online. My latest Data Points column dives into some of the new XML features in SQL Server 2005 including typed columns and schema collections. I also discussed the TRY/CATCH exception handing features and DDL triggers (which can access event data in an XML format).

    You can read the article online here.

     

    In the upcoming issues I'll be discussing several of SQL Server Reporting Services 2005’s features.

    Posted Apr 24 2006, 11:31 AM by John Papa with 1 comment(s)
    Filed under: ,
  • SQL Server and ADO.NET in Toronto

    Man have things crept up on me! This past weekend I reviewed my code sample for my presentations at VSLive in Toronto later this week. It should be a good show up in Canada … I enjoyed my trip there last time. For any of you who will be there, here is a brief glimpse at what I will be discussing/demonstrating:

    Developing with SQL Server 2005 – Part 1 (April 26th, 10:30 am)

    • XML Data Type
    • XML Schema Collections
    • FOR XML
    • Querying with XQuery
    • Modifying data with XQuery

    Hard Core Coding with ADO.NET 2 (April 26th, 2:00 pm)

    • New Features and Major Changes in ADO.NET 2
    • DataTable Enhancements
    • DataTableReader
    • Batch Updates
    • Bulk copying techniques
    • Performance Enhancements

    Developing with SQL Server 2005 – Part 2 (April 26th, 3:15 pm)

    • Exception Handling
    • EventData
    • Triggers
    • Common Table Expressions
    • Views and Derived/Inline Tables
    • DRI Enhancements

     

    The agenda is now online for VSLive Toronto right here. All of my sessions in Toronto are on April 26th. I’ll be presenting 2 sessions on developing with SQL Server 2005 and a 3rd session on developing using ADO.NET 2. If you are planning on attending the conference, please stop by and say hi!

    Posted Apr 24 2006, 11:30 AM by John Papa with no comments
    Filed under: , ,
  • Trivia - Microsoft Code Names

    Recently I was having a conversation with some colleagues of mine from Microsoft when I confessed that often I am more confused by the code names of the software products than I am by the technology.

    Does anyone remember Cairo? Chicago? Whistler? Forgot Sphinx and Yukon already? Anyway, Terrence Dorsey sent me an interesting bit of trivia regarding the code names that I received his permission to post here. He explains a bit of background on where some of these code names propoertedly come from.

     

    Disclaimer time …. Terrence nor I stand behind the ultimate validity of these code name derivations

     

    Quoted from Terrence

    MSFT code names have never been particularly imaginative.

     

    Orcas is an island in Puget Sound. It is a popular vacation spot for Microsofties of a certain age, hence its reference as a code name. Same story for Whidbey.

     

    Legend has it that, some years ago, a group of Windows PMs was talking about strategy over drinks after a day of skiing. They decided XP (the release being planned at that time) would be code named Whistler after one of the local ski areas, and the "next" version of Windows ten or so years down the line would be called Blackcomb after the ski area on the next mountain. An interim "dot" release was expected, and it would be named Longhorn after the bar in which they were drinking (and which happens to be half-way between the two mountains).

     

    Blackcomb was long ago dropped as a code name, though it still pops up from time to time. My take is that it remains for some folks a convenient name for "stuff to do in a release down the road."

     

    Prior to Windows ME (confusingly code named Millennium, which was its actual name), Windows division used the name of the city in which the OS was announced as the code name.

     

    eHome division has maintained the Whistler/Blackcomb theme by code naming its release after specific ski runs on the mountain. (I just learned that from Ask.com. Also according to according to Ask.com and other sources, the code name Vienna is currently being used for two different projects. Ick.)

     

    So there you have it …I am not alone in my confusion

     

  • Practical .NET 2 & C# 2 - First Impressions

    I got my copy of Practical .NET 2 and C# 2 about a month ago and with my reading list as it is, I have bouncing around between several books. Some good, some bad and some in between. So I finally got to reading a good chunk of Practical .NET 2 and C# 2 by Patrick Smacchia (the 10 first chapters) and it certainly has its moments. So far I have found it to be a very good book that makes may dry topics move very quickly.

    The publisher is Paradoxal Press … a virtual unknown in our industry. And I believe this is their first book in the .NET development space. With that said, overall I have no major complaints about how the book is put together. There are several grammatical errors in the book that I believe should have been caught by the editors, but this is a minor issue.

    The author, Patrick Smacchia, is a Microsoft MVP and he touches on a wide variety of topics in this book. I as very skeptical at first seeing that the book covers so much of .NET … I was afraid it was another one of those books that discusses everything but at such a high level it leaves you wanting at every turn of the page. This book is over 800 pages and through the first 10 chapters I have found it to be very interesting as it discusses the .NET framework and its foundation. Much of this may be a review to many readers, but I found that I did not want to skip pages to quickly just in case there was something new I could pick up on a topic I was already familiar with. Despite its density, I have found the book fast moving so far.

    I like the way the author explains topics, very direct and to the point. He general describes a topic, why the topic is important, where it is useful and then gives examples on who to use it. This is a not a editorial book like some others I have read lately ... the author is more focussed on explaining  .NET than he is on amusing the reader. Perhaps this is why it reads so fast.

    Up through chapter 10 the book has focussed on the .NET Framework v2 and the basics of objects in .NET. The rest of the book gets more into the features such as generics, ADO.NET, remoting, polymorhpism, inheritance, base classes, and transactions. So far this book strikes me as a good reference to explain how things work in .NET both under the covers and on the surface. This book lacks practical everyday examples on using may features (so far, thru chapter 10) and instead focuses on explaining what the features are, how they work and where they might be used. This is not a flaw of the book but rather a categorization of it. We sometimes buy books as a reference and other times we buy them for specific problems that we want to solve. This book falls in the former category.

    I recommend this to any .NET developer who wants to fill in the gaps and get a solid understanding of the .NET Framework v2. For someone who has written all or parts of 8 books I am impressed with Patrick’s ability to keep the topics flowing along at a pace that both maintains the interest of the reader and manages to get deep enough into each topic. Through chapter 10, this book gets 4 stars out of 5 for me.

  • IIS Default Web Site Won't Start!

    So I am playing around with the Telerik controls, the LINQ preview and C# 3.0 code, some demos I am creating for the upcoming VSLive conferences and some work for my job … when all of the sudden my web site won’t start. I rebooted my PC (the fix all solution) but it still would not start. Hmmmm. I figured it had to be something I just installed but it turned out to be something else entirely. Something I installed (or reinstalled) a few weeks ago … Skype.

    It turns out that Skype was binding itself to my ports so IIS could not start my default web site on port 80. Now why this just started happening tonight I may never know. But thanks to a post I found on Matthew Cosier’s Blog it pointed me to Skype.

    As soon as I went into the options of Skype and went to view the connection settings, I unchecked the checkbox that allows Skype to use port 80 and 443. I then shut Skype down and turned it back on and all was well. My web site started just fine this time. I like Skype, but man that is annoying. Thankfully a quick Google search found Matthew’s post and i only lost about 15 minutes of time. I’m reposting it so future victims will have double the chances to get a hit on Google.

  • SCOPE_IDENTITY() and @@IDENTITY Demystified

    I’ve run across several applications where the use of IDENTITY values has caused some confusion, specifically in how the @@IDENTITY function operates given external influences. We’ve all likely been faced with how to grab the newly generated IDENTITY value from a SQL Server database table. And there are a 2 popular techniques that accomplish this with SQL Server:

    1. the @@IDENTITY function
    2. the SCOPE_IDENTITY() function

    They both will return a newly generated ID value but the difference between the 2 is very important. Important enough that you could get back an ID that you did not desire. The @@IDENTITY function returns the last IDENTITY value that was generated in your connection. So if you are running a stored procedure that looks something like this (using the Northwind database):

    CREATE PROCEDURE prRegion_Insert_1

    @description NCHAR(50)

    AS

        INSERT INTO Region (RegionDescription) VALUES (@description)

        SELECT @@IDENTITY

    GO

    Assuming that your database has no other actions that occur between the INSERT statement and the SELECT @@IDENTITY statement, then you will get back the newly created RegionID value for the new Region row. But what if there is n Insert Trigger, for example, on the Region table that inserts a record into another table that also has an IDENTITY column. (Perhaps it does this to audit data.) In this case, the sequence of events would be:

    1. the stored proc fires
    2. insert the new region record
    3. the trigger fires
    4. the trigger’s code inserts the audit record
    5. the stored proc then executes the SELECT @@IDENTITY, which then returns the ID that was created by the last statement, which is the audit table’s ID

    In this case, the ID returned is the ID value that was created by the insert statement inside of the trigger. You might say that you would never put a trigger on a table that inserts into a table with an IDENTITY column in the first place. And I’d believe you … However … other developers and database administrators may create a trigger in the future that does this. They might not know that you wrote a stored procedure (or series of them)  that relies on this situation not occurring. The point is that “stuff” happens (polite way of saying it).

     

    So what does SCOPE_IDENTITY() do? It returns the last IDENTITY value generated in the scope. So what is the scope? The scope is a batch of SQL code such as s stored procedure, a trigger, or a user defined function. Using the previous example, the scope is the context of the stored procedure and not anything that gets called indirectly by it such as a trigger. This allows you to grab the last generated ID in the stored procedure, as you likely intended for it to happen. Here is another stored procedure that uses the SCOPE_IDENTITY() to grab the last ID generated in the Region table.

    CREATE PROCEDURE prRegion_Insert_2

    @description NCHAR(50)

    AS

        INSERT INTO Region (RegionDescription) VALUES (@description)

        SELECT SCOPE_IDENTITY()

    GO

    Is it magic? Nah. But sometimes the smallest things can have huge impacts on our applications.

     

     

     

     

    Posted Apr 07 2006, 02:29 PM by John Papa with 30 comment(s)
    Filed under:
More Posts