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

Raymond Lewallen

Framework Design, Agile Coach, President Oklahoma City Developers Group, Microsoft MVP C#, TDD, Continuous Integration, Patterns and Practices, Domain Driven Design, Speaker, VB.Net, C# and Sql Server

April 2005 - Posts

  • DTS migration to SSIS

    From Tom Rizzo’s blog, here is some news I knew I would have to go looking for sooner or later but I just haven’t had time to go research SSIS regarding what’s going to be involved in converting DTS packages.

    Q) How do I move to SSIS?
    A) It's a migration.  We have a migration wizard that will take your DTS packages and migrate them to SSIS.  The thing you have to remember is that SSIS is not a minor upgrade to DTS.  It's a re-write to make SSIS super scalable and have great performance and functionality.  The good thing is that we still ship the DTS 2000 runtime in certain versions of SQL Server 2005 so you can continue to run your DTS packages even as part of a SSIS workflow.

  • A few changes from Beta 1 to Beta 2 when writing code for SQLCLR

    First of all, if you only downloaded the standard Visual Studio 2005 Beta 2, you will have have available the “New Sql Project”.  You must download the VSTS in order to get the professional version where you will find sql projects in visual studio.

    So I took some of my SQL Server projects from Beta 1 and moved them to Beta 2.  A few things you’ll want to be aware of, and looking in the April CTP of MSDN will not provide you the answers. 

    The old System.Data.SqlServer namespace has been replaced by Microsoft.SqlServer.Server in Beta 2.  The server side provider has been merged with the client side, so you no longer reference sqlaccess.dll.

    SqlContext.GetPipe has changed to just SqlContext.Pipe.  That one was easy enough to find.

    This was a bit harder, as I kept looking and looking for it.  You can no longer do SqlContext.Connection/Command etc.  If you done some of this in Beta 1 you’ll remember using SqlContext.GetCommand which returned a command object within the current context.  That has alltogether been removed.  Now you obtain a connection by using SqlConnection conn = new SqlConnection("Context Connection=true"); or Dim conn As SqlConnection = New SqlConnection(“Context Connection=true”) in VB.  By including the parameter Context Connection, this provides the same functionallity as SqlContext.GetCommand was providing.

    Pablo Castro over at Microsoft wrote an article up on MSDN here for more information.

  • What design patterns are you using?

    On our forums somebody posted about trying to implement an n-tier solution, which quickly led into a comment from Jake on design patterns.

    So, I’d like to do a little survey.  What design pattern(s) dominate your software models?  What are you really doing?  You can go to this link and view some of the more popular patterns.

    Like many of you, abstract factories, factory methods, adapter and template methods dominate my world.  Singletons come in handy, especially for state management, as do many other patterns, but they don’t dominate the structure of my code the way the others do.

  • Refactoring pattern quiz number 1 answered

    Here is how to refactor (or at least how I refactor, there are other ways) this example I posted earlier.  The class Foo can pretty much be implemented however you want.  In my case, I wanted to get the number of required tokens for a specific person using an interface.  You can see that I created in interface IPerson that contains GetNumberOfRequiredTokens.  This way I can just pass in an IPerson object type and use the polymorphed, overriden function in the child class, or adult class (each of which inherit from the Person class that implements the IPerson interface).  I implemented a property in the base class that contains the default number of tokens, and then for each derived class, I use that along with custom calculations the derived class to come up with the appropriate number of tokens required.

    The refactoring pattern we are targeting here is called “conditional to polymorphism”, along with a few other names.  The goal was to refactor our initial “Select Case” into a base class with derived classes.  This increases usability and scalability greatly over our initial code we started with.

    Don’t forget, and I did not demonstrate this, you will ALWAYS want to write a unit test for your initial code (Foo.GetNumberOfRequiredTokens) and make sure it passes all scenarios BEFORE beginning your refactoring process and DURING and AFTER your refactoring process.

    To test this, create a new object of type Adult.  Then call Foo.GetNumberOfRequiredTokens(adultObject) and it will return 3.

    Refactored: conditional refactored to polymorphism

     

    Public Class Foo

     

        Public Shared Function GetNumberOfRequiredTokens(ByVal person As IPerson) As Int32

            Return person.GetNumberOfRequiredTokens()

        End Function

     

    End Class

     

    Public Interface IPerson

        Function GetNumberOfRequiredTokens() As Int32

    End Interface

     

    Public MustInherit Class Person : Implements IPerson

        Private baseTokenAmount As Int32 = 1

        Protected ReadOnly Property Tokens() As Int32

            Get

                Return baseTokenAmount

            End Get

        End Property

     

        Public MustOverride Function GetNumberOfRequiredTokens() As Int32 Implements IPerson.GetNumberOfRequiredTokens

    End Class

     

    Public Class Child : Inherits Person

        Public Overrides Function GetNumberOfRequiredTokens() As Int32

            Return MyBase.Tokens()

        End Function

    End Class

     

    Public Class Adult : Inherits Person

        Public Overrides Function GetNumberOfRequiredTokens() As Int32

            Return MyBase.Tokens * 3

        End Function

    End Class

     

    Public Class Infant : Inherits Person

        Public Overrides Function GetNumberOfRequiredTokens() As Int32

            Throw New TooYoungException

        End Function

    End Class

     

    Public Class TooYoungException : Inherits Exception

     

    End Class

  • Refactoring pattern quiz number 1

    Here is a pattern I'm sure we all see quite a bit. Nothing wrong with it really. Small, clean, simple. However, when you take into context the fact that the following code is part of an entire program used to manage carnival rides, how would you refactor the following code? No need to post code, an explanation will do. I'll post the answer and the code in a little while.  This is one of the more straight-foward and obvious patterns to recognize in the context given.  Those of you new to OOP, it may be harder to see.

    Part of a carnival program

     

    Public Class Foo

     

        Private baseTokenAmount As Int32 = 1

     

        Public Function GetNumberOfRequiredTokens(ByVal typeOfPerson As PersonType) As Int32

            Select Case typeOfPerson

                Case PersonType.Infant

                    Throw New Exception("Too young to ride")

                Case PersonType.Child

                    Return baseTokenAmount

                Case PersonType.Adolescent

                    Return baseTokenAmount * 2

                Case PersonType.Adult

                    Return baseTokenAmount * 3

                Case PersonType.Senior

                    Throw New Exception("Too old to ride")

            End Select

     

        End Function

     

        Public Enum PersonType

            Infant

            Child

            Adolescent

            Adult

            Senior

        End Enum

     

    End Class

     

  • What happened to New Sql Project in Visual Studio 2005 Beta 2?

    Ok, this is pretty annoyning.  I have Visual Studio 2005 Beta 2 installed along with Sql Server 2005 April CTP.  So I want to create a new stored procedure in C# to use in sql server.  Click New/Project and look around.  Hey!  No new sql server project!  What happened here?

    So now I take my old C# stored procedures and open them up in Beta 2.  Don't try to convert from Beta1 to Beta2, it won't convert a single file of your project.  So I create a new project and add my old files to it.  Naturally, there are all types of compile time errors.  Most notably, that have moved System.Data.SqlServer to Microsoft.SqlServer.Server.  Ok, easy enough to deal with.  Change a couple of statements (GetPipe() is now just a read only property called Pipe, if I remember correctly from last night).  Now everything seems to be OK, except one thing.  I can't find what they did with SqlContext.GetCommand.  That was pretty important, as it returned a sql command object within the current context.  For the life of my have not been able to find out where that went.

    So now what, we can't build UDFs or stored procedures in Beta2 now?  Even the April CTP of MSDN still references the Beta1 namespaces, so no help there.  Cannot find anything on the internet regarding these changes or what we're supposed to do in order to build sql clr code in VS Beta 2.  If anybody has any information, I'd be most grateful.  If I find any more information on this, I'll post it here.
  • CodeBetter Public Forums Are Now Online

    I have just put up our initial set of forums here at CodeBetter! You will see mostly general and most often discussed forums surrounding .Net and Sql Server technologies. I'm sure I'll be adding more in the near future, such as SharePoint and BizTalk forums, along with forums for discussing Agile methodologies, which is one of my personal favorites, and probably one of Darrell's too. In the meantime, please check them out and leave a comment here or use my contact page and let me know if you want to see something additional included in the forums.

    This will be a great way to interact with not only the CodeBetter team, but also with your peers from around the world.

  • Scott Dockendorf speaking about Test-Driven Development

    Monday, May 02, 2005 in Oklahoma City, OK. Speaker: Scott Dockendorf speaking about Test-Driven Development .NET Today

    In this session, "Test-Driven Development & .NET Today!”, Scott will provide an overview of Test-Driven Development ("TDD"), and it's role in improving software development and reducing defects through automated unit testing. While TDD is a core foundation for Extreme Programming ("xP"), it can be effective under any programming methodology.  During this session, Scott will demonstrate TDD’s test-first approach, debugging unit testing assemblies with VS.NET, using NUnit.

    Go to the Oklahoma City .Net Developers Group website for more information.

  • A nice thing about Sql Server 2005 Express and RANU

    There are some new features around SQL Server Express 2005 (SSE) which allow you to treat your database just like a file. You can add the .MDF file to your project and then when you go to deploy your app it travels with it like a file so you don't have to worry about setting up a database on a server. This is similar to Access but with the power of SQL Server.  I believe this is how RANU (run as normal user) is supposed to work. Each user on the machine gets their own instance of SQL Express.  The way RANU works is that it looks in the exe's current folder for the .MDF file. When you debug and build your app in VS the exe is actually run from a subfolder so VS has to copy the .MDF to the same location. This requires you to put the .MDF in the project so that the project system knows to copy the file on a build. So the "short" answer is that there will be one copy to put it into your project folder, and then another copy to the build location on build or debug. There is a Copy to Output Directory property on the file which allows you to specific if you want to do the copy everytime or just when the .mdf file in the project changes.  So at runtime if I have a 1 GB database it is going to get copied around at that timeHowever, you can turn off this functionality. This is also specific to the designtime features. Runtime will work against an absolute path so you can avoid the copies if desired. It is expected that most databases won't be that large so it works pretty well for getting started with the feature.  Thanks to Eric on the Visual Basic Data Team at MS for the information on RANU! 

  • Oklahoma City bombing 10th Anniversary

    This is not of techinal nature, but wanted to post anyways here for you all to read.  For those of us who live in Oklahama City, today is a day of rememberance, as it is for all Americans.  9:02 CST this morning marks the 10th anniversary of the bombing in which 168 men, women and children lost their lives.
  • Pitfalls when installing Visual Studio 2005 Beta 2 with Sql Server 2005 Beta 2?

    Getting ready for the installation of VS2K5B2.  Just setup a new Virtual PC, with the help of Eric and this article by Mark (no, I’ve never used Virtual PC before.  Never had a need when I’ve got 5 computers at my fingertips).  Installed a brand new base operating system virtual hard drive for Windows XP so I have a clean slate.  I already have the ISO for VS, but don’t have any blank DVDs :(  I will have to stop at the store and pick some up.  My next step is to go out and update my VPC OS with the latest and greatest updates from Windows Update.  I’m wondering about the .Net Framework 2.0 though.  I also plan on installing Sql Server 2K5 on the same VPC and am wondering which to install first.  The Sql Server with 2.0 framework or the VS2K5 with the 2.0 framework?  How good is the beta 2 of Sql Server going to be with an updated framework installed?  Hopefully there will be no adverse effects.  Perhaps I should run a seperate VPC with the Sql Server 2K5B2 installed, but I only have 1 GB RAM available and am worried about the lagging effects of running 2 VPC instances, but this may be the only way to do it right when installing VS2K5B2 and SQL2K5B2.  I already have standalone machine with VS2K5B1 and SQL2K5B2 installed, and don’t have any problems running them both on the same PC.  Dare I try it now that VS2K5B2 is out?  Any thoughts on this?  I’m hoping some of you spent your precious weekend time doing the exact same thing I’ll be doing tonight and may have some suggestions on how to approach with a minimal amount of work.

    Also, happy blogday to me.  This is my 100th post!

    Update: Just found this link from Denis Bauer that pretty much answers all my questions on this. You'll have to have Sql Server April CTP for it all to play nice together it seems.

  • I thought managed code would keep me from losing my hair

    In the last 2 months or so, I have had an exponential increase in the amount of hair that is falling off my head.  For about 6 years I kept my head shaved and it was nice and comfortable.  Then my hair started to thin a little bit.  So I had a conversation with my hair that went something like this:

    Me: “Hey, hair, yeah, where are you going?”

    Hair: “Well, if you’re just going to keep cutting me all off, I don’t see any reason to hang around.”

    Me: “Wait, wait.. let’s talk about this for a minute.  I don’t want you to leave.”

    Hair:  “What are you going to do?  I feel unloved.  Unwelcome here.”

    Me: “Let’s reach a compromise.  How about if I let you grow for awhile, would you feel better?”

    Hair: “Hmmmm… I guess we can try that out, but no promises.”

    So there we were.  I felt as though we had reached some sort of agreement.  I would let the hair grow for awhile, and hair would stick around and feel welcome and loved again.  And I have had less stress in my life over the last few years.  Managed code makes life so neat, simple and carefree that I was essentially worry free.  I was in programming bliss.  Life was good.  I still had hair.

    So then about 3 weeks ago or so I was washing my hair (yes, I wash my hair more often than that) and looked at my hands.  My hands looked like I had just strangled a wet rat.  And now they look like that everytime I wash my hair.  So I’m in a position that I must take evasive action.  Rogaine?  Propecia?  Voodoo?  What’s a poor balding guy to do?  My hair let me down.  It led me to believe that if I let it grow it would be happy and stick around.  What a cruel joke that turned out to be.  At this rate, I’ll be completely bald in about 12 weeks.  And my hair is laughing all the way down the drain (causing the water to drain slower and slower on a daily basis).  Why can’t I lose facial hair instead?  That would be ideal.

    So now I’m going to change shampoos.  Change conditioners.  Probably research into rogaine.  Do some research and find out exactly what I need to do to slow the process.  Oh, and by the way, my father is not bald.  My mother’s dad never went bald and my father’s dad is not bald.

    In the meantime, I’m going to blame BCLs and the delay of VS2K5.  The BCLs are just so freaking huge and maybe trying to learn them all is a good excuse for my hair falling out.  Waiting on VS2K5 sounds like another good excuse.  Maybe once it arrives my hair will quit falling out, but I may be bald by then.

  • Here is a quote that reflects how I feel about SOA

    Came across this article by Grady Booch. One short paragraph sums up how I feel about service oriented architecture.

    “…SOA is just one part of establishing an enterprise architecture, and those organizations who think that imposing an SOA alone will bring order out of chaos are sadly misguided. As I've said many times before and will say again, solid software engineering practices never go out of style (crisp abstractions, clear separation of concerns, balanced distribution of responsibilties) and while SOA supports such practices, SOA is not a sufficient architectural practice. “

  • A successful software project can be one that is never started

    What is the most important piece of a successful software project?  The development of the software.  Programming.  Development.  Coding.  The majority of time, resources and energy are focused on the coding of the software for a project.

    Do you know what else can be considered a successful software project?  The one that never gets developed.  Let’s say a customer comes to you with a problem and you present a solution that involves the development of a custom software package.  You have an idea of the amount of money the customer is able to spend, the resources available, the scope of the project, time needed to complete and many other factors.  Once everyone involved evaluates requirements and the risks involved, the decision may be made that the project not go forward.  This is a successful project.  The right decision was made given all the input and variables.  You did your part: gather requirements, evaluating scope, estimating time, money and resources.  By making good decisions you’ve probably saved the customer a lot of anguish because they didn’t realize in the beginning what all may be required (resources, time, money, quality, scope).  You’ve helped your customer by helping make a good and appropriate decision not to continue the project at this time.  In the future, when aspects of the customers business (again: resources, time, money, quality, scope) change, the customer is likely to come back to you to again re-evaluate the customers requirements and needs again.  Perhaps this time the right decision will be to go ahead and do the project.  Everybody wins, everybody is happy.  You avoided a possible disaster by not getting greedy and not taking into consideration the customers stance.  I’ve seen very bad things happen because of situations where developers convinced their customer to invest the time, money, resources etc into a project that in the end turned out poorly because of change of scope, decrease in quality, risk assesments that are too high and “risky” that get ignored or other reasons.  These are reasons that good and frequent meetings and evaluations during a planning phase can help avoid.

  • Operator Overloading in VB.Net 2.0

    The .Net framework version 2.0 brings many new things to developers in all languages. This has been talked about quite a bit, but I just wanted to refresh everybody on one of things I know I'm looking forward to. Operator overloading.  If you've done any programming in C#, none of this is new to you.  If you are strictly VB.Net, or new to any .Net language, then read on.

    Operator overloading is the act of making something happen when somebody wants to use an operator, such as + (plus sign) to add two or more objects together. At present, you can't do this in VB.Net in fx 1.0, 1.1. Let's look at how we accomplish adding objects together in current release versions of VB.Net

    The VB.Net 1.1 way

    Public Class RoadTrip

     

        Public Sub New()

        End Sub

     

        Public Sub New(ByVal milesTraveled As Int32)

            CheckValue(milesTraveled)

            _miles = milesTraveled

        End Sub

     

        Private Sub CheckValue(ByVal value As Int32)

            If value < 0 Then Throw New ArgumentOutOfRangeException("Value")

        End Sub

     

        Private _miles As Int32

        Public Property Miles() As Int32

            Get

                Return _miles

            End Get

            Set(ByVal Value As Int32)

                CheckValue(Value)

                _miles = Value

            End Set

        End Property

     

        Public Shared Function Add(ByVal roadTripOne As RoadTrip, ByVal roadTripTwo As RoadTrip) As RoadTrip

            Dim newRoadTrip As New RoadTrip

            newRoadTrip.Miles = roadTripOne.Miles + roadTripTwo.Miles

            Return newRoadTrip

        End Function

     

    End Class

    Nothing wrong with that.  Just pop in an add function and we get the functionality that we want.  Consider a slight drawback.  The API user has to know there is an Add method, which intellisense pretty much provides to the user, so its really not even a drawback.  Let’s implement the above code:

    Implementing the above 1.1 code

    Public Sub ShowExample()

            Dim roadTripOne As New RoadTrip(100)

            Dim roadTripTwo As New RoadTrip(250)

            Console.WriteLine("Road trip one was {0} miles.", roadTripOne.Miles)

            Console.WriteLine("Road trip two was {0} miles.", roadTripTwo.Miles)

            Dim totalTrip As RoadTrip

            totalTrip = RoadTrip.Add(roadTripOne, roadTripTwo)

            Console.WriteLine("Total trip was {0} miles.", totalTrip.Miles)

        End Sub

    The output

    Road trip one was 100 miles.

    Road trip two was 250 miles.

    Total trip was 350 miles.

    What operator overloading allows us to do is not have the Add method, but include an operator that performs the same actions.  In this case, it will be + (plus sign)

    The VB.Net 2.0 way

    Public Class RoadTrip

     

        Public Sub New()

        End Sub

     

        Public Sub New(ByVal milesTraveled As Int32)

            CheckValue(milesTraveled)

            _miles = milesTraveled

        End Sub

     

        Private Sub CheckValue(ByVal value As Int32)

            If value < 0 Then Throw New ArgumentOutOfRangeException("Value")

        End Sub

     

        Private _miles As Int32

        Public Property Miles() As Int32

            Get

                Return _miles

            End Get

            Set(ByVal Value As Int32)

                CheckValue(Value)

                _miles = Value

            End Set

        End Property

     

        Public Shared Operator +(ByVal roadTripOne As RoadTrip, ByVal roadTripTwo As RoadTrip) As RoadTrip

            Dim newRoadTrip As New RoadTrip

            newRoadTrip.Miles = roadTripOne.Miles + roadTripTwo.Miles

            Return newRoadTrip

        End Operator

     

    End Class

    Implementing the above 2.0 code

    Public Sub ShowExample()

            Dim roadTripOne As New RoadTrip(100)

            Dim roadTripTwo As New RoadTrip(250)

            Console.WriteLine("Road trip one was {0} miles.", roadTripOne.Miles)

            Console.WriteLine("Road trip two was {0} miles.", roadTripTwo.Miles)

            Dim totalTrip As RoadTrip

            totalTrip = roadTripOne + roadTripTwo

            Console.WriteLine("Total trip was {0} miles.", totalTrip.Miles)

        End Sub

    The output

    Road trip one was 100 miles.

    Road trip two was 250 miles.

    Total trip was 350 miles.

     All in all, in my opinion, easier to write, easier to read, easier to understand.

More Posts Next page »