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

Grant Killian's Blog

No, this has nothing to do with beer -- but maybe it should?

January 2004 - Posts

  • MySQL and .Net

    I've noticed more and more customers getting into MySQL instead of paying for SQLServer.  For the record, I much prefer developing with SQLServer because there are many features MySQL doesn't have; that being said, MySQL has an attractive price tag for inhouse application development -- free -- and offers the basics.  I generally side with Frans Bouma's post about Stored Procs adding a new API to maintain in your application; I use a data-entity framework that constructs SQL statements in memory, based on class metadata.  It's very slick and I never have to worry about porting an app from SQLServer to MySQL (or elsewhere) because it's plain vanilla SQL.  Now, I still end up writing Stored Procedures from time-to-time, but only when the customer intends to be tied to SQLServer.

    The following link is a good one for connecting to MySQL with .Net: http://www.mysql.com/articles/dotnet/ (although the site to download dbProvider from eInfoDesigns is dead --hopefully only temporarily!).  I've had success with the MyODBC driver, but I'm following the MySQLConnection work that's going on at SourceForge -- still in beta but it won't be for long.

    Of course, when Yukon becomes available the gap between SQLServer and MySQL will broaden.  From what I've read about Yukon, it sounds like the term “Database” takes on new meaning to Microsoft -- they've added whole layers of functionality that MySQL can't compete with.  SQLServer development will dramatically change, and sticking to “plain vanilla SQL” will surely become less attractive and productive . . . but for now, with MySQL, it's not a bad substitute.

    Happy .Netting!

  • Using the GC

    I tackled Garbage Collection last year here and even here.  Let me add a little more to the subject, prompted by an emaiI I got from a buddy.  If I create sample windows project with a single button on the form and add the following code . . .

     private void button1_Click(object sender, System.EventArgs e)
      {
       TestObj obj = new TestObj();
       obj.WriteSomethin( "text" );
       GC.Collect();
       GC.WaitForPendingFinalizers();
       doStuff();
      }

      private void doStuff()
      {
       for ( int n = 1;  n <= 5; n++ )
       {
        System.Threading.Thread.Sleep( 1000 ); //simulate long running operation
        System.IO.StreamWriter sw = new System.IO.StreamWriter( @"C:\Test.log", true );//append to file
        sw.WriteLine( "Iteration " + n );
        sw.Close();
       }
      }
     }

     public class TestObj : IDisposable
     {
      ~TestObj()
      {
       AllDone();
      }
      public void Dispose()
      {
       AllDone();
      }
      private void AllDone()
      {
       System.IO.StreamWriter sw = new System.IO.StreamWriter( @"C:\Test.log", true );//append to file
       sw.WriteLine( "TestObj Destroyed " + System.DateTime.Now.ToShortTimeString() );
       sw.Close();
      }
      public void WriteSomethin( string strStuff )
      {
       System.IO.StreamWriter sw = new System.IO.StreamWriter( @"C:\Test.log", true );//append to file
       sw.WriteLine( strStuff );
       sw.Close();
      }
     }

    If you run it, click button1, and check out C:\Test.log BEFORE closing the application you'll get this:

    text
    Iteration 1
    Iteration 2
    Iteration 3
    Iteration 4
    Iteration 5

    It looks like our Destructor doesn't fire because no “TestObj Destroyed” message is in the file, even though the method has gone out of scope.  Only by closing the application does the Destructor actually fire (and log “TestObj Destroyed 5:03 PM”) -- all this even with our statements:

       GC.Collect();
       GC.WaitForPendingFinalizers();

    Which should “empty the finalizers” queue and trigger our GC.  It doesn't trigger TestObj destruction; the important point is that I don't have control over exactly when my object will be collected by the runtime.

    Add a second button to the form and place this code in the code-behind:

      private void button2_Click( object sender, System.EventArgs e )
      {
       using( TestObj obj = new TestObj() )
       {
        obj.WriteSomethin( "text" );
       }
       doStuff();
      }

    Run the app and click the second button.  “Hold on!“ you might say, it looks like it's disposing multiple TestObj objects because we get multiple “TestObj Destroyed 5:03 PM” messages; not to worry, comment out the explicit c# destructor (the “~TestObj” function) so that our object only writes a message once upon object finalization.  Then run the application and check the log file:

    text
    TestObj Destroyed 5:13 PM
    Iteration 1
    Iteration 2
    Iteration 3
    Iteration 4
    Iteration 5

    Much better.  The more control I have, the happier I am.  Our TestObj is destroyed upon the termination of our using() statement scope.  Plus, button2_click doesn't explicitly call GC.Collect and GC.WaitForPendingFinalizers -- unless you have a really good reason, it's unwise to call these methods.  Letting the .Net Framework manage the memory is usually preferred.

    For more on GC, including a bit on WeakReferences, check out the MSDN articles: http://msdn.microsoft.com/msdnmag/issues/1100/gci/
    http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/

    Happy .Netting

  • The good ol' days of Response.Write and Server.CreateObject

    One of the many projects I'm working is an ASP classic app; we're extending it with new ASPX functionality, which is interesting in its own right, but as I peruse the ASP codebase I'm constantly struck by how primitive old school ASP feels compared to developing for the .Net framework. 

    With ASP, a modest form of object orientation (through VBScript Classes) and code reuse is achieved through this web of include files.  I remember doing my share of this development back in the day, and considered it cutting edge then; we created some sophisticated stuff!  Around 1998-1999, me and a colleague had this cool idea where we'd place all our logic in COM components for ease of debugging (remember trying to debug in InterDev on a remote server?) and compiled performance -- plus, we'd be able to reuse DLLs easier than a convoluted web of include files.  We took the idea further, and called it “VBML” where we'd have proprietary tags (“<VBTABLE src="“tblDataBaseUsers“/">” etc.) that rendered as special content (all generated by our COM components); every asp page would run through our proprietary “magic parser.”  100% generated HTML.  We had MTS rolling, SQL Server, and thought this was as brilliant as beer in a bottle!

    In retrospect, we were marching down the same path as the Microsoftians.  Our VBML never took final shape, it was always a work in progress with lots of theoretical elements we never got around to implementing.  Thank goodness Microsoft did --  and then some.  The .Net platform introduced powerful elements like the cache, viewstate, and a new Page processing model our VBML hardly anticipated -- us amateurs were barely scratching the surface!

    Anyway, I think all that ASP classic experience, the VBML years included, serves me well.  I understand the underpinnings of the .Net framework and appreciate the measures it takes to ensure proper component versioning, etc.  People new to .Net, without the hard-earned perspective many years of Response.Write and Server.CreateObject() provide, are at a serious disadvantage when doing more sophisticated .Net development.  Experience counts for a lot in this industry, even if it's in a different platform or language!

    Happy .Netting!

  • BITS (Background Intelligent Transfer Service)

    BITS Article : http://msdn.microsoft.com/msdnmag/issues/03/02/BITS/default.aspx

    Collection of BITS resources: http://www.faqshop.com/misc/default.htm?http://www.faqshop.com/misc/miscbits.htm

    BITS is intriguing to me.  Does anyone have anything good/bad to say about BITS (Background Intelligent Transfer Service)?  It's now available for Win 2003 Server for download and upload of files!  Offers interesting options for file transfer scenarios (touched upon in my post here -- particularly the comments).  It uses any “extra“ bandwidth available to the machine, so responsiveness must not be a key requirement. 

    Back to my cave . . .

    Happy .Netting!

  • Devscovery, anyone?

    This has been on my radar screen for a while, but I want to point it out to developers in the mid Atlantic.  Wintellect is putting on a conference in DC in April, dubbed Devscovery.  It's 3 days of .Net, .Net, and a bit more .Net.  The topics took like a good balance of in depth presentations on the current version of .Net and previews of the next version Whidbey.

    If DC isn't close enough for you, in August they'll be in Redmond, in September they'll be in Atlanta, and in October they'll be in Austin, Texas.

    By the way, www.WeProgram.Net is giving away a conference pass to one lucky member -- details to follow soon!

    Happy .Netting!

  • httpRuntime and File Upload Limits

    Still reeling from a flood of New Year work.  Let me offer something brief.  Rob Spitzer did a nice Win2K3 and IIS 6 presentation for WeProgram.Net last night.  We were discussing some Win2K to Win2K3 migration issues, and besides this Response Buffer issue I discussed here, I mentioned some default settings regarding file upload size.  Donny Mack wrote about using the httpRuntime element in web.config here, but in a nutshell let me share that web.config supports an <httpRuntime> element under the system.web section -- specifically something like this

    <httpRuntime maxRequestLength="10000" />

    will establish a max file upload size of 10,000 Kilobytes.  You can set this more broadly in your machine.config, too.

    Oh, yeah, Admin and Developer alike might find SAM's Windows Server 2003 Delta guide useful.  Amazon it here.  If my word isn't good enough, both Rob Spitzer (local Admin extraordinaire) and Darrell Norton (local Developer extraordinaire) highly recommend it too!

    Happy .Netting

  • Holiday Hangover

    Whew, I need a vacation from my vacation.  The two weeks in Denver and Boston were great, I got to spend good time with family and friends, but it's tough balancing everything.  I even worked a good bit while on “vacation.”

    I have a tutorial on DotNetJunkies that was published over the holiday, it's a follow up to the post I made here about custom server control creation.  I got enough emails from people who wanted me to follow through on the custom control example, so I finally gave in.  I had to crank the article out very quickly, so I'm not 100% happy with it, but DotNetJunkies needed it in short order.  In my opinion it's > mediocre but < fantastic.  Check it out and judge for yourself.

    Speaking of material cranked out quickly, I've been looking over ASP.Net 2.0 Revealed by Patrick Lorenz (he purportedly wrote the base copy in 6 weeks time).  Those crazy Germans.  It seems very rough around the edges (with typos and editing oversites), but speaks to Whidbey topics in a very direct manner and I kind of like the fact that it's not so polished.  I've also been reading through A First Look at ASP.Net 2.0 by Homer, Sussman, and the illustrious Rob Howard.

    Both books seem pretty good -- they collectively made up for me not having Whidbey installed over the holiday break . . . installing Whidbey is on my list of todos for January since an upcoming project will require it (it's a long story...).  Unfortunately, my workload will likely prevent me from doing the INETA development I wanted to do.  Maybe later this Winter.  More later.

    Happy .Netting!

More Posts