david's profileDavid Yardy PE, MCSD.NET...PhotosBlogLists Tools Help

Blog


    January 25

    .NET 3.5 SP1 : How to tell if it is installed?

    Ever want to know if you have 3.5 SP1 installed?  Shown below are two ways to determine.

    1.) Take a look at HKLM\SOFTWARE\MICROSOFT\NET Framework Setup\NDP\v3.5

    Shown below are two servers.  The top one does not have SP1 installed while the lower one does.

    image

    2.) An easy way to see if you have 3.5 SP1 installed is to navigate to http://www.hanselman.com/smallestdotnet/ Near the top of this page you will be given an indication if you have the latest installed.

    image

     

    If you do not have it installed you can use the following link to navigate you to Microsoft Downloads for Microsoft .NET Framework 3.5 Service Pack 1.  This link will installed a small installer that will need to be executed.  A wizard will step you through the installation and additional downloads.

    If you prefer a complete download of this SP1 you can use this link.

    December 07

    String Literals and C#

    I was looking for some utility that would take a very long string and convert it to vb.net or c# with line continuation(s) characters. String literals to the rescue.  C# supports two forms of string literals: regular string literals and verbatim string literals. 

    A regular string literal consists of zero or more characters enclosed in double quotes, as in "hello", and may include both simple escape sequences (such as \t for the tab character) and hexadecimal and Unicode escape sequences.  In c# regular strings can only span multiple lines with syntax similar to the following:

    string sql = “SELECT customer “ +
                      “FROM customers “ +
                      “WHERE custId=10”;


    A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character. A simple example is @"hello". In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence. In particular, simple escape sequences and hexadecimal and Unicode escape sequences are not processed in verbatim string literals.

    The above sample can be replaced with the ‘literal’ designated by the @ symbol as follows:

    string sql = @“SELECT
                      FROM customers
                      WHERE custId=10”;

    July 11

    New Blog Location

    I have moved my web log to the following location http://blog.davidyardy.com/

    My RSS feed can be found at http://feeds.feedburner.com/davidyardy From this RSS feed you can view all log entries on my new and old blog location.

    It was time to move my blog back to my own domain.  It was on that domain for quite a while then as it was short some features I moved to Spaces.  Now once again I am back to my own territory/domain.  Given a little time I hope to re-brand the blog and related web site.

    June 17

    Coding Emails on Vista

    Microsoft removed the SMTP server on Vista.  As a result any email testing on your development box will need to address this change.  Most developers will discover this through some exception after they try to run their application locally.

    Two options

    1. Use a free SMTP Server product locally http://softstack.com/freesmtp.html or http://www.smartertools.com/Products/SmarterMail/Free.aspx.  Both of these are very lightweight are quite simple installations.
    2. My preference is to configure mail settings to use a pickup directory.   See below…

    Mail Settings Configuration – add the following to your web.config.  After making the modifications to your web.config all emails sent will be in .eml file format.  There are a number of benefits such as no more waiting for emails to be sent and also that you can monitor all emails generated from your application.

    <system.net>
      <mailSettings>
        <smtp deliveryMethod="SpecifiedPickupDirectory" from="no-reply@mydomain.com">
          <specifiedPickupDirectory pickupDirectoryLocation="C:\temp\emailOutput\" />
        </smtp>
      </mailSettings>
    </system.net>

    Check it out.

    June 16

    Vista – Fix Folders

    You may have noticed that if you modify the view settings for a folder in Windows Vista and then for some reason some graphics files are dropped in the directory the view settings will be reset.  I have struggled with this for a year.  I would keep setting the view defaults (showing date modified etc.) and then a week or so later the columns would reset.  Well, here is the fix for this. 

    Save the following code in a file with the .bat extension and run this file.

    setlocal

    set BASE_KEY=HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell

    :: Delete cached folder views
    reg delete "%BASE_KEY%\Bags" /f
    reg delete "%BASE_KEY%\BagMRU" /f

    :: Set default folder template
    reg add "%BASE_KEY%\Bags\AllFolders\Shell" /v FolderType /d NotSpecified

    :: Restart Explorer
    taskkill /f /im explorer.exe
    start explorer.exe

     

    Well worth the small effort.

    Consolas for you Command Prompt

    Use the following reg add command to add the Consolas to your command prompt window

    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont" /v 00 /d Consolas

    In the end after opening the defaults for the command window you end up with a very pleasant change.  This tip looks like it has been around for a while but I recently stumbled upon it.

    image


    image

    May 14

    Vista and Visual Studio: Error: Web site worker process has been terminated by IIS

    "The web server process that was being debugged has been terminated by Internet Information Services(IIS).  This can be avoided by configuring Application Pool ping settings in IIS."

     image

      Very easy fix by following these instructions....

    1. Open the Administrative Tools window.

    2. Click Start and then choose Control Panel.

    3. In Control Panel, choose Switch to Classic View, if necessary, and then double-click Administrative Tools.

    4. In the Administrative Tools window, double-click Internet Information Services (IIS) Manager.image

    5. In the Internet Information Services (IIS) Manager window, expand the <computer name> node.

    6. Under the <computer name> node, right-click Application Pools.

    7. In the Application Pools list, right-click the name of the pool your application runs in, and then click Advanced Settings.

    8. In the Advanced Settings dialog box, locate the Process Model section and chose one of the following actions:

      1. Set Ping Enabled to False.

        —or—

      2. Set Ping Maximum Response Time to a value greater than 90 seconds.

      Setting Ping Enabled to False stops IIS from checking whether the worker process is still running and keeps the worker process alive until you stop your debugged process. Setting Ping Maximum Response Time to a large value allows IIS to continue monitoring the worker process.

    9. Click OK.

    10. Under the Services and Applications, click Services.

      A list of services appears in the right-side pane.

    11. In the Services list, right-click Terminal Services and then click Properties.

    12. In the Terminal Services Properties window, locate the General tab and set Startup type to Manual.

    13. Click OK to close the Advanced Settings dialog box.

      Close the Internet Information Services (IIS) Manager window and Administrative Tools window.

    May 12

    MVC Resources - including links to UI MVC Validation

    MVC is a framework methodology that divides an application's implementation into three component roles: models, views, and controllers.  Interested...check out the following very excellent list of resource that can be found here

    May 10

    Visual Studio AddIn RockScroll

    Very nice add-in which modifies the vertical scrollbar inside of Studio 2005/2008.  The download is small and can be turned off very easily through the Tools-Add Ins menu.

    DownloadDownload Rocky Downs' RockScroll for Visual Studio

    RockScroll

    No more toolbars and buttons! - Keyboard only!

    If you are a user that lives in an application day-in/out you must force yourself to learn the shortcut keys (at least until voice recognition becomes efficient).  For developers, simply remove the toolbars which immediately forces you to the shortcuts.

    Very quickly you will notice clear clutter free IDE.

    If you need assistance use the following to help out Visual Studio 2005 Keyboard Shortcut Posters

    May 03

    Windows Explorer (add to your tools menu) in Visual Studio

    I often need to open Windows Explorer and browse to the current file, folder, or project that I am working on in Visual Studio. This tip allows you to achieve this by clicking "Windows Explorer" in the Tools menu, and is one of the most simple-yet-useful tips I know of.

    To set it up, click Tools, then External Tools..., then click Add.  Now enter the following data:
    Title: Windows Explorer
    Command: explorer.exe
    Arguments: /select,"$(ItemPath)"

    Leave Initial directoy blank, and click OK.  Now when you click Tools, Windows Explorer, Windows Explorer will open with the current file you are editing selected.

     

    Adding Windows Explorer to the toolbar

    image

    Right click on toolbar and select customize.   Select 'Tools' and if you have not added other External tools then select "External Command 2".  After you drag External Command 2 to the standard toolbar it will change to Windows Explorer.

    image



    I have also set the Alt-E key to open Windows Explorer also by selecting "Keyboard" and finding Tools.ExternalCommand2 and setting Alt-E as the shortcut.


    image

    Label to a form input field

    If you set a label to a form element set the AssociatedControlID property. This will force the label to render as <label> rather than <span>. A benefit of using the AssociatedControlID property is that clicking a label when this property is set automatically changes the form focus to the associated form input.

    May 01

    Visual Studio 2008 Offline Support

    When saving files from within Studio I was prompted  to "Save As", "Overwrite", or "Cancel".  I thought it was very odd.  I then looked around and noticed that none of my files displayed the typical source control lock.  It looked like my solution was not connected or related to source control.

    For some reason I had lost my connection to Team Foundation (Source Control).  Confused for a little... I then noticed that VS.NET 2008 had this "Go Online" option. 

    Nice...offline support for source control is now built into Studio 2008.  In 2005 there was an add-on tool to review and reconnect disconnected files to source control.

    After selecting "Go Online" Studio 2008 will check the solution for changes while you were offline and will show a dialog window with the differences.  Now, when checking in you will see those files that you modified while offline as files that need to be checked in.

    April 26

    Windows Vista Shortcuts - Tips

    1.) Did you know that in Windows Vista you can launch all the shortcuts in you quick launch bar by clicking the “Win” button + a number (”WIN” + 1 will launch the first link from the left and so on…)?

    2.) Create a shortcut to the application you want to run with the shortcut by right clicking the executable file and selecting “Create shortcut” from the menu.

    Right click on the shortcut that was created, and select properties.

    All you need to do is go over to the Shortcut key line and select your desired shortcut.  For instance I have made the F1 and F2 function keys open Internet Explorer and Firefox respectively.

    image

    3.) If you need to configure more keyboard shortcuts check out GoHeer.com - Keyboard ShortCuts application

    April 25

    Using LINQ (Language Integrated Query) - got to have this tool!

    What is LINQ to SQL? - implementation of the IQueryable interface over the SQL Server Schema
                                      - generates queries directly against the schema objects (pretty much 1 to 1)
                                      - queries returning objects (strongly typed experience over Sql Server Schema)

    Visual LINQ Query Builder is an add-in to Visual Studio 2008 Designer that helps you visually build LINQ to SQL queries.

    Functionally it provides the same experience as, for instance the Microsoft Access Query Builder, but in the LINQ domain.

    The entire UI of this add-in uses Windows Presentation Foundation. The goal of this tool is to help users become more familiar with the LINQ syntax.

    The tool may also demonstrate to users how to create their own Visual Studio 2008 add-in using Windows Presentation Foundation.

    You can find this tool here and nice walk through of the tool on Mitsu's blog.

    image

    April 23

    DevConnections 2008 Orlando - (Day 3) Sessions

    Miscellaneous Tips/Tricks

    Encapsulate Common Code (Ultimate Base Page Class http://tinyurl.com/2mjyud)

    Avoid Storing Config Settings in <appSettings> - http://tinyurl.com/2lr6vw

    • not strongly typed
    • cluttered
    • risk of collisions

    Register Controls in web.config

    • Custom Controls

      <pages>
         <controls>
            <add tagPrefix="aspalliance" assembly="AspAlliance.Web.UI.Controls" />
         </controls>
      </pages>
    • User Controls

      <pages>
          <controls>
             <add tagPrefix="user" src="~/UserControls/LeftNav.ascx" />
          </controls>
      </pages>

    Favor Hyperlinks over LinkButtons

    Avoid Excessive use of Label

    • label renders with span tags and has viewstate by default doubling bandwidth footprint
    • use Literal or <%= Variable %> instead

    Avoid Passing DataReaders

    • open and close (and dispose) datareaders in the same method
    • use using() and commandBehavior.CloseConnection
    • if you must pass between methods use delegate pattern (http://aspalliance.com/526)

    Visual Studio Tips

    • Autocomplete variable names with ctrlspace
    • Hold down ctrl to make the Intellisense
    • window transparent so you can see your code
    • Ctrl-K, Ctrl-D to reformat code
    • Ctrl-. will add using statements
    • Add shortcut to remove/sort using statements (Ctrl-Alt-O)

    Tools/Products

    DevConnections 2008 Orlando - (Day 2) Sessions

    ASP.NET 3.5 New Things

    New Controls

    • ListView (supports binding/editing/selecting/deleting/paging/sorting and complete control over html)
    • DataPager (adds paging support to other controls (currently only ListView, customizable UI)
    • LINQDataSource (Binds to any LINQ enabled data model)
    • ASP.NET AJAX built in to VS.NET 2008

    Visual Studio 2008 Enhancements

    • multi-targeting support
    • javascript intellisense
    • javascript debugging
    • AJAX Control Extender Support
    • Web Designer and CSS Support
    • Nested Master Page Support
    • Vertical Split View (good for multi-monitor)

    ASP.NET MVC (Model-View-Controller)

    • Enables much better testability of web applications
    • Provides complete control over output of web application
    • Very few working controls, no viewstate

    ADO.NET Data Services

    Easily makes data easily available to other clients via http

    .NET & Silverlight Client Libraries

    • Microsoft.Data.WebClient namespace (WebDataContext, WebDataQuery)
    • Query with LINQ or Object Services
    • All CRUD operations available

    LINQ the defining feature in .NET 3.5

    • LINQ is an expression parser (implemented via Extension Methods) i.e. Select(), .Where(), .GroupBy()
    • Core LINQ Language Features
      • Anonymous Types (dynamic type creation)
      • Type Inference (var)
      • Object Initializers (default value assignments)
      • Extension Methods (extend existing classes with new methods)
      • Lambda Expressions (simplified predicate or expression syntax)

    LINQ to SQL (Database to Entity Mapping)

    • maps database schema to object schema
    • simplified 1 - 1 mapping (tables -> entities)
    • LINQ to SQL Designer allows customization

    LINQ over Entity Model

    LINQ TO SQL is not Business Layer - one of the challenges of LINQ is to establish appropriate business layer approach.  No place to hook up business logic in model.  No multi-tier logic abstraction.  Essentially two-tier if used in UI directly.  There are some techniques to establish or wrap LINQ to establish business layer behavior.

    ASP.NET Custom Controls with AJAX

    AJAX Control Options

    • Build a control from scratch (ultimate in flexibility but can be time consuming)
    • use ASP.NET AJAX Extensions classes as a foundation (require custom mapping of server side and client side properties)
    • use the ASP.NET AJAX Toolkit control framework (simplifies control development but requires AjaxControlToolkit.dll assembly)

    AJAX Extensions Steps

    1. define/register control namespace
    2. create control with constructor and private properties
    3. create control properties with prototype design pattern
    4. dispose of resources
    5. register type with ASP.NET AJAX Script Library

    AJAX Toolkit Extension Control

    1. Reference AjaxControlToolkit.dll
    2. Create server control and derive from ExtenderControlBase
    3. Reference embedded script control using WebResource and ClientScriptResource attributes
    4. Map properties using ExtenderControlProperty

     

     

    April 22

    DevConnections 2008 Orlando - Day 2 (CLR in SQL Server 2005)

    CLR in SQL Server 2005

    CLR Option (disabled by default, once enabled it is hard to turn off)

    CLR Code can be used in…

    • Stored procedures, Triggers, Functions, Aggregates, UDTs, Reports

    But Should it? - consider performance, security and development issues
    Extended Stored procedures (SQL 2000) are excellent candidates for application of CLR Technology.

    Where Does CLR Technology Fit?

    • To replace existing Extended Stored Procedures
    • For complex mathematical formulas
    • For access to .NET Framework functionality (i.e. encryption)
    • As an interface to non-standard data sources
    • CLR-based User-defined types
      • Permit smarter, more complex data types

    Challenges

    • No control over 'safety' of code created (all or nothing)
    • Database Dependencies - once a udt is used, dependencies must be removed before it can be changed
    • Visual Studio support - more complex development to integrate

    CLR Assemblies designate security level

    • SAFE (the default)
      • No external system resource access (code not trusted)
      • VS.NET 2005 assumes permission Level = Safe (anything but safe means the CLR can blue screen SQL Server server.
    • EXTERNAL_ACCESS
      • Permitted to access specific external resources (code has provisional trust)
    • UNSAFE
      • Permitted to access anything (code fully trusted)

    Development of more complex CLR assemblies requires build scripts to tear down dependencies and recreation.

    Comparisons of performance must be done through SQL Enterprise Manager (as opposed to VS.NET).  VS.NET adds a lot of overhead to performance information and thereby skewing the end results.

    User Defined Types (defined with VS.NET in managed language)

    • Serialization - taking properties of UDT and save out as bits into backing store (serialization provided by VS.NET only is functional with fixed length data types)
    • De-Serialization - taking bits and populating properties of UDT

    DevConnections 2008 Orlando - Day 2 (Getting Started with Entity Framework - EF)

    A common design pattern for data modeling is to divide the data model into three components

    • Conceptual Model - defines the entities and relationships in the system being modeled
    • Logical Model - normalizes the entities and relationships into relational database tables with foreign key constraints
    • Physical Model - specifies engine-specific storage details such as partitioning and indexing

    The ADO.NET Entity Framework expands the power of the conceptual model by enabling developers to write code that operates against objects generated from an Entity Data Model (EDM) instead of directly against the logical (relational) model. The Entity Framework then maps those operations to storage-specific relational commands.

    Benefits

    • developers can develop against a model independent on underlying storage mechanics
    • mappings between the model and physical structure can be performed without changing code
    • multiple models can exist for a single storage schema
    • model has features such as strong typing with type hierarchies, navigable relationships, and complex types.

    Getting Started with Entity Model

    Key Aspects

    • Conceptual mapping - logical layers
    • Entity Data Model (EDM)
    • Entity Client
      • ADO.NET data provider that exposes data in terms of a conceptual Entity Data Model, queried through a common Entity SQL language
    • Entity SQL
      • SQL based query language extended to express queries in terms of EDM
    • Object Services
      • Providing services such as state management, change tracking, identity resolution, loading and navigating relationships, propagation of object changes to database modifications, and query building support for Entity SQL
    • LINQ for Entities
      • Allows you to write LINQ queries through Entity Client to return data

    Entity Framework Compared to LINQ to SQL

    • LINQ is rapid development
    • Direct 1:1 mapping of classes and schema
    • Can override CRUD methods
    • SQL Server DB

    Entity Framework Highlights

    • Write less data access code
    • Reduce maintenance (maintenance is done through UI with EM)
    • Abstracts structures into Object Oriented model

    Querying the Entity Framework

    • Entity Client with Entity SQL
      • Flexible string based syntax (good for getting back data based on dynamic requests (i.e. search page))
      • Ado.net data provider
      • No entities
    • Object Services with Entity SQL (more dynamic)
      • Flexible string based syntax
      • Can return objects
    • LINQ to Entities (more dynamic)
      • Strongly typed syntax
      • Can return objects

    Editorial: This technology is the one that has been missing from Microsoft in the last x years.  In lieu of this framework there have been a number of other technologies (i.e. NHiberate, Subsonic, CSLA.net etc.).  In short this is Microsoft's Enterprise level object relational/mapping product.  It is currently in beta but is to be released this summer.  In short EF provides wizards that aid in the mapping of database tables (currently only SQL Server but other vendors Oracle/MySQL are already building providers to hook up) and maps them to database objects.  It differs from LINQ to SQL in the fact that it builds a model that is now available for additional manipulation such as merging tables, filtering tables and creating additional tables build from query/view or stored procedure.

    Modifications to the underlying database require updates to the model but with custom code in partial classes this can be done with very little effort. 

    Currently, only the primary entity is serialized through WCF but in the following release child objects will be serialized through WCF without any data loss.  At the current time, this can be managed through passing the primary object in list object with child objects in related list object.  This can be accomplished with wrapper for transmission of the entity through serialization process.