Thursday, February 26, 2009

Work – Are you anonymous

I thought that this post by G L Hoffman was a good one on how to stand out at your work-place.rope Read the post – it is good. And I have reproduced the points here for easy perusal.

1. See work. Dont wait for work to be assigned to you. Seek out work to do. There is always more work to do!

2. On time.

3. Be perfect. Strive towards perfection, understanding that no one is perfect.

4. Can Do. Those with the Can Do attitude are the ones that will get ahead and will be the ones that upper management will seek out.

5. Do the job no one else wants. Be the one that is considered to be toughest to get the hardest jobs done.

6. Be sales minded. Always look for ways to add value to your company.

7. Customer-focused. Enough Said!

8. Always improve. To get ahead, you certainly cannot be stagnant, look for ways to improve professionally and personally.

9. Don’t whine, gossip or complain. Need anyone say more?

10. Become an evangelist. Goes to (6).

And while you are looking at the above list, why not look at this list for programmers:

  • Never stop learning.
  • Communication is critical.
  • Under promise, over deliver.
  • "I was wrong."
  • If it is not tested it doesn't work.
  • Programming isn't your job, shipping is.
  • From: Fatherly Advice To New Programmers

    Monday, February 23, 2009

    DOS: Renaming files with today’s date

    Was asked by someone if there was an easy way to rename a file with today’s date and here is one way to do that:

    Copy the following command into a batch file and save it as dateRenamer.bat

    for /f "tokens=1-4 delims=/ " %%d in ("%date%") do rename %1 %%g%%e%%f_%1

    And you call it so: dateRenamer test.txt
    And it will rename the file test.txt to 20090223_test.txt.


    To see what the for command is doing, check out:, and the gist is:

    Split the date into 4 tokens, (starting with token name d and ending with g) using the delimiters “/” and space. %date% date formatted like: mon 02/23/2009 and hence d becomes the day, e the month, f the day and g the year. These variables are then used to create the new file name.

    The one thing you will notice is that the date is pre-pended to the original file name. I did this because I could not come up with an easy way to break down the name of the file-path into filename and extension. By pre-pending the date to the file name, I avoid the issues of having to split the file name.

    Sunday, February 15, 2009

    YAMB – using it to split MP4 files

    YAMB (Yet another MP4 Box utility), allows you to do many things with your MP4 files. I needed it to chop a long video into 10 minute pieces so that I could upload it to YouTube. YAMB can do it, but it does not have any documentation. So when it came to setting a value into the “Split by duration” box, I had no idea what kind of value it takes.


    Well, after a whole lot of tries, I figured out that to split my video into 10 minutes pieces, the value had to be 600 (10 minutes x 60 seconds). Ah! so the value it accepts is in seconds.

    But, after spending at least 5 minutes, trying various values, I found that YAMB has tool-tips (only if the delay to display them was not so high, I might have found them a long time ago!). And it turns out the values you can specify for the “Split by Duration” box are

    1. In seconds

    2. Using the format hh:mm:ss.ccc (when using this format – be sure to add the values for ccc – otherwise YAMB will freak out. eg: 10 minutes = 00:10:00.000)


    Here is a good tutorial on how to manipulate and edit your MP4 files: (page 5, goes into how you can use the YAMB tool).

    Wednesday, February 11, 2009

    ASP.Net – Using SQL Server to store SessionState - Error

    You have done everything that needs to be done (installed the tables, stored procs, etc in to the Database and updated the web.config file) and yet you get a message that ASP.Net Session State is not installed:

    Unable to use SQL Server because ASP.NET version 2.0 Session State is not installed on the SQL server. Please install ASP.NET Session State SQL Server version 2.0 or above. "

    Turns out the most likely cause could be that you do not have the correct permissions set on your database. You need to provide the user who is accessing the database containing the ASP.Net Session State objects execute permission, so that it can run the stored-procs to access and manipulate the state information stored in the tables.

    The easiest way to do this, is to right click on your database object in Sql Server Management Studio (SSMS), go to permissions and grant execute to the user that will be used to connect to the database.



    When creating the ASP.Net 2.0 session objects do not run “InstallSqlState.sql” directly. I found this to be unreliable and the file itself tells you not to do it that way. Also do not run the “aspnet_regsql.exe” via its GUI – I found that to not work always to. Instead run aspnet_regsql at the command prompt (executable is found in the %windir%\Microsoft .Net\Framework\version folder).

    Here is the command I used:

    aspnet_regsql.exe -ssadd -sstype c -S ServerName -d customDBName –E

    -ssadd: create a database to support the storage of session information in SQL Server -sstype c: create a custom database to store the session state info. (Otherwise a ASPState database will be created/reused). I prefer this – as it allows me to keep my session state databases separate for different applications. -S: server name -d: database name – required as I had specified –sstype c. (Otherwise name defaults to ASPState) -E: use windows integrated log-in. (Instead you could use –U and –P to specify the SQL Server username and password to connect to the database). The options for aspnet_regsql are case-sensitive. MSDN documentation for ASPNet_RegSql

    Because I used the –sstype c option, I need to add the “allowCustomSqlDatabase” property to the sessionState node and set it to true in the web.config file. (This is because you will need to provide the actual connection string, instead of just the user id and password, which is the default format for the sqlCOnnectionString property).

    <system.web> <sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="Data Source=ServerName;Initial Catalog=DataBaseName;Persist Security Info=True;User ID=userID;Password=pwd;"/>

    Tuesday, February 10, 2009

    DNN – My very first DNN project

    I am a newbie with DotNetNuke (DNN) and here is what I needed to do to getting it up and running.


    1. Even though VS 2005 & VS 2008 come with a development web-server (Cassini), DNN folk suggest using a IIS sever for development. So go ahead and install IIS on your machine. (You will need WinXP pro to install IIS though, which I have on my work machine and if you have Vista, I think you will need the home premium edition at a minimum to get IIS).
    2. The best way to start working with DNN is to use their starter kit, which installs Visual Studio templates, that will make life a lot more easier when creating DNN sites. (
    3. SQL Server 2005 (or 2008).

    Starting off:

    1. Create your new DNN site by going to File –> New –> Website.
    2. Select “DotNetNuke Web Application Framework” under templates. (if you cannot see this template – make sure that the language selected is Visual Basic and that you have the starter kit installed).
    3. Select HTTP as your location type and for the path, type in a value such as “http://localhost/DotNetNuke Website”. (This will create a folder under your InetPub/wwwRoot folder with the name DotNetNuke Website). Hit OK. VS will churn for a while and create all the files that you need to run a DNN site.
    4. You arent done yet.
    5. You need to run DNN once to get it to setup your database. I am using a SQL Server 2005 instance, running on a separate server. You can use SQL Server Express running on your local machine instead.
      Create a new database on your SQL Server. Set the owner to a login that has db_owner granted on it.
      Create the connection string for the database you just created. (Tool coming soon, until then, use VS’s server explorer – create your connection and then check the properties for the connection and you should be able to copy out the connection-string created by VS for you.)
    6. Open up the web.config and update the “SiteSqlServer” value with the connection string from (5). There should be 2 places that you need to update this value:
      ConnectionString and AppSettings.
    7. Set the default.aspx file in the root of the website as the start-up file.
    8. Hit CTRL+F5 to start the app without debugging. If everything went correctly up to this stage, you should see the installation page. If not, go to the beginning and see if you missed a step (permissions on folders and database are typical causes). If you cannot get the installation page – then you are out of luck on this post!
    9. Once the installation page is up and running, select the typical installation option. On the next page, DNN should have picked up most of the settings from the SiteSQLServer key in the web.config file. You will have to type in the database password. The rest of the settings for the installation are pretty mundane.

    Problems I had:

    • After creation and installation of DNN, when I tried to run DNN, I got 6 errors – all of them relating to “DotNetNuke.FckHtmlEditorProvider.dll”:
      • Could not load type 'DotNetNuke.HtmlEditor’.
      • Could not load type 'DotNetNuke.HtmlEditor.FckHtmlEditorProvider.fckStyles'.
      • Could not load type 'DotNetNuke.HtmlEditor.FckHtmlEditorProvider.fckimagegallery'.
      • Could not load type 'DotNetNuke.HtmlEditor.FckHtmlEditorProvider.fckCSS'.
      • Could not load type 'DotNetNuke.HtmlEditor.FckHtmlEditorProvider.fcklinkgallery'.
        To get it working again, all I had to do was move the “DotNetNuke.FckHtmlEditorProvider.dll” from the BIN\Providers folder, to the BIN folder.
    • Error about website not being able to view the directory.
      • This is most probably because you havent set the default.aspx as the start up page.
    • Various errors about files and folders:
      • Check your folder permissions. I gave the local ASPNET and NetworkServices account modify privileges on the website folder and all its children.

    Monday, February 09, 2009

    Installing SQL Server 2005 Management Studio

    I made the big mistake of installing VS 2005 before installing SQL Server 2005 management studio. The result: I was unable to get SQL Server to install the management studio on my machine. It would crap out each time saying that it could not upgrade my existing installation.

    After trying many, many different things that had been blogged all over the web, here is what I had to do, to get SQL Server 2005 to install Management Studio on my machine.

    Here is what you need:

    The SQL Server 2005 installation DVD or if you are using the CD images, then you need Disk 2.

    Open a command prompt and browse to the folder “Setup” and run the following command:

    SqlRun_Tools.msi UPGRADE=Client_Components

    Under client components, select Management tools.

    And run the installer.

    If you get a message regarding a different version of SQL Server books being installed on your machine, put a check box in front of the message and click next to begin installation.

    Hopefully at this point, the installer will finish and you should have management studio installed on your machine.

    If SQL Server 2005 management studio did not install on your machine, then try the following:

    Go to Add/Remove programs and click change.


    In the dialog that pops up, click on the link “To install a new component, click here”


    This will bring up a browse dialog. Browse and select the “Setup.exe” file on the installation media. (Remember if you are using the CD images, you need to use disk 2).

    Select Management Tools on the Feature Selection page


    Complete the installation.

    Hopefully, by doing one of the above steps – you will get SQL Server 2005 Management Studio to install on your machine, without having to go through the laborious process of uninstalling VS 2005, installing SQL Server 2005 and then installing VS 2005. What a royal pain….


    Sunday, February 08, 2009

    Thursday, February 05, 2009

    log4Net – Logger not working?

    If you are using log4Net for the first time in your application and logging is not working, then first check if you are calling:


    Configure() needs to be called only once during the lifetime of your application and a good place for you to insert it in a ASP.Net web-app is in the global.asax file’s Application_Start method.

    Here is a basic log4Net configuration for the web.config file that you can test for basic log4Net issues.

    Right under the <configuration><configSections> tag, add the following code:

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net,Version=,Culture=neutral,PublicKeyToken=1b44e1d426115821" requirePermission="false"/>

    Next add the following log4Net configuration section:

        <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
            <threshold value="DEBUG" />
            <evaluator type="log4net.Core.LevelEvaluator,log4net">
              <threshold value="DEBUG" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
            <appender-ref ref="EventLogAppender" />

    Finally call the following code – to see if your event log gets populated with some events.

    log.Debug("Debug Message");
    log.Info("Info Message");
    log.Error("Error Message");


    Still having problem?

    Turn on log4Net’s internal debugging. Easiest way to do this is to add the following KV pair under <AppSettings>:

    <add key="log4net.Internal.Debug" value="true" />

    And then add the following text as a child of <configuration>:

        <trace autoflush="true">
                initializeData="logs\trace1.txt" />

    This will spew out log4Net’s trace information to a file called “trace1.txt” under the logs folder of your app.

    Trace not giving you any information?

    Try and move the log4Net settings to a separate file.

    Once the log4Net settings are in a separate file, call “log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath(null) +\\log4net.xml));” in your Global Application_Start method, instead of log4net.Config.XmlConfigurator.Configure(); as shown earlier.

    Most of the above information is available at:

    Tuesday, February 03, 2009

    ASP.Net – How to manually start Web Dev Server (Cassini)

    Cassini is the web developer server that is provided with Visual Studio (2005 & 2008) for debugging and testing ASP.Net websites. It is normally started by Visual Studio, whenever you attempt to debug an ASP.Net web-app.

    Sometimes you just need to be able to run the web-dev server, without having to load up Visual Studio and here is a simple way to do that:

    Create an empty bat file (I created mine on the desktop – and you will see why in a little bit…)

    Copy and paste the following code into the bat file:

    call "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sdkvars.bat" "C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe" /port:3900 /path:%1

    Now, whenever you want to start the web-dev server, all you need to do is drag and drop the root folder of your web-site onto the bat file.


    This will automatically start up Cassini.

    image Right clicking on the web-dev icon and choosing “Open in web-browser”, will open up InternetExplorer, allowing you to view your web-site. image note: if you do not have default.aspx in your root folder, the web-browser will list all the contents of the folder, you can then manually click on the aspx file that you wish to see running within the dev-server.

    ASP.Net – Exportable Encryption of web.config (server farms)

    Alternate title for this post: Encrypting web.config for IIS server farms.

    ASP.Net in version 2.0 of the .Net framework introduced the ability to encrypt configuration information using “Protected Configuration Providers”. ASPNET_IISREG.exe (ASP.Net IIS Registration Tool) is used to encrypt web.config files from the command line. (To do it programmatically – look at the System.Configuration namespace as well as this example:

    For more information check out MSDN documentation for Protected Configuration.

    Examples abound on the Internet on how to encrypt web.config files. Almost all of these examples expect that you have a web-site setup on the computer where you wish to encrypt the web.config file. Instead I wanted a series of steps that would allow me to encrypt the web.config files on my development computer and then push it out to the test/production machines. And this post documents the steps to do just that. Such a procedure is also helpful when deploying your web-app to a server farm environment – where you cannot depend on a machine specific key for the encryption and decryption of the web.config contents.

    1. Create RSA key container (Development machine).

    aspnet_regiis -pc "testRSAKeyContainer" -exp
    -pc: creates the key pair named “testRSAKeyContainer” and installs it for all users -exp: makes the key pair exportable 2. Export the RSA key container (Development machine).
    aspnet_regiis -px "testRSAKeyContainer" "c:\keys.xml" -pri
    -px: exports the key container “testRSAKeyContainer” to the location “c:\keys.xml” -pri: ensures that both private and public keys get exported 3. Prepare the web.config file for encryption (Development machine). Add the following code to the web.config file as a child of the <configuration> node (I prefer to do this before the ending configuration tag, as it looks cleaners).
              <add name="SampleProvider" type="System.Configuration.RsaProtectedConfigurationProvider,
              System.Configuration, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
    The important parts that need to be configured by you are underlined. name: This is the name for the configuration provider that you are creating in this section. keyContainerName: This is the name of the key container that you created in step 1 and exported in step 2. The <configProtectedData> section is used by ASPNET_IISREG.exe to determine how the web.config file will be encrypted.

    4. Encrypt the web.config file (Development machine).

    First, make a backup of the web.config file! Typically there are 2 sections that will be encrypted for most applications: connectionStrings and appSettings. If there are other sections that need to be encrypted, then make a note of those names. (The web.config is encrypted one section at a time, which is why you will require a list of sections that need to be encrypted).

    If you need to encrypt the connectionStrings section, run the following command:

    aspnet_regiis -pef "connectionStrings" "c:\webAppPhysicalLocation" -prov "SampleProvider"
    -pef: encrypt section connectionStrings in web.config located at “c:\webAppPhysicalLocation” -prov: name of configuration provider specified in web.config file that will be used to encrypt the section. Specified as the name in step 3. Similarly, if you need to encrypt the appSettings section, run the following command:
    aspnet_regiis -pef "appSettings" "c:\webAppPhysicalLocation" -prov "SampleProvider"

    The following steps will be performed on each machine where your web-app will be deployed.

    6. Import the RSA Key container into the machine. (Deployment machine) Copy the “keys.xml” file to the machine where the app needs to run. Run the following command to import the keys:

    aspnet_regiis -pi "testRSAKeyContainer" "keys.xml" -exp

    -pi: imports the keys in keys.xml for all users on the machine and names it “testRSAKeyContainer”. (Just to be on the safe side, be sure to use the same case for the name that was used to create the container in step 1 – it might be case-sensitive). -exp: imports it such that the key container is exportable. (important to be able to decrypt the web.config file)

    note: In a server farm environment, you will import the key container into each machine that participates in the server farm.

    7. Deploy the encrypted web.config file (Deployment machine)

    Copy the encrypted web.config file from step 4 to the machine where the web-app is going to run. Run the application and test to make sure that you are able to decrypt the web.config file.

    note: In case your application fails to start up with a configuration error, see step (3)’s note above.

    Important Note: In some environments you will have to give the account that runs the web-app (typically ASPNET) permission to access the key container. This is done with the following command:

    aspnet_regiis -pa testRSAKeyContainer ASPNET

    Notes: 1. To delete a key container that has been installed to a machine, use the following command:

    aspnet_regiis -pz "testRSAKeyContainer"

    2. To test decryption: Decryption of a protected web.config file occurs on the fly. The easiest way to test it is to create an aspx file with the following text and run it from within a browser. Expects an AppSettings section with a key value pair for SecretValue1 and a ConnectionStrings section with a connection string named MyAppConnString.

    <%@ Page Language="C#" %>
      Response.Write(ConfigurationManager.AppSettings["SecretValue1"] + "<br />");
      Response.Write(ConfigurationManager.ConnectionStrings["MyAppConnString"].ConnectionString + "<br />");
    Alternatively, you can run the following command which will decrypt the specified section (connectionStrings in this case) in the web.config file directly.

    aspnet_regiis -pdf "connectionStrings" "C:\webAppPhysicalLocation"
    The process of decryption using the code in the aspx file and the aspnet_regiis -pdf command is a powerful set of tools that can aid you in determing the cause of problems that are occuring with the use of encrypted configuration files. Especially in a server farm environment, it lets you know if the keys have been correctly imported to all the machines participating in the farm and if the web.config file has all the correct settings. 3. Location of key containers:

    Depending on how the key containers were installed (per user/for all users), there are 2 separate locations where the key containers are kept: Per User: C:\Documents and Settings\<user_name>\Application Data\Microsoft\Crypto\RSA All Users: C:\Documents and Settings\all users\Application Data\Microsoft\Crypto\RSA

    On Vista machines, the location of the container files is: Per user: C:\Users\<user_name>\AppData\Roaming\Microsoft\Crypto\RSA All Users: C:\Users\All Users\Application Data\Microsoft\Crypto\RSA

    The files cannot be read as plain text, but if you look through the first few lines, you will be able to determine the names of the key containers on the machine.

    4. The following configuration sections CANNOT be encrypted:

    • <configuration>
    • <configProtectedData>
    • <system.runtime.remoting>
    • <runtime>
    • <startup>
    • <mscorlib>
    • <processModel>
    • <satelliteassemblies>
    • <cryptographySettings>
    • <cryptoNameMapping>
    • <cryptoClasses>

    5. In case you get a Configuration error while running your application with the following error message: An error occurred loading a configuration file: Could not load file or assembly 'System.Configuration, Version=, Culture=neutral' or one of its dependencies. The system cannot find the file specified. Then it is most probably because you are missing the PublicKeyToken in the definition for the provider.

    6. In case you get an error that the key container could not be opened, check 2 things: - the account that runs the site has permissions to the key container and - the keycontainername specified in the web.config file is the one that exists on your machine.

    Other info:

    Extremely detailed steps on encryption of configuration sections:

    Scott Mitchell article:

    MSDN documentation:

    Monday, February 02, 2009

    When your software warrants a crack!

    Cocomo-II-Application-for-Software-Cost-Estimation-CASE-0 Many moons ago I created a software for the Windows PDA called CASE (COCOMO II Application for Software Estimation). I think the year was 2002!

    And today someone sent me a link to a crack that had been created to get around paying for the application:

    If imitation is the best form of flattery, shouldn't the act of someone creating a crack for your application, be just as flattering! ;)

    COCOMO II was based on this Barry Boehm book.



    ps: I strongly discourage you from trying out the link – I am sure it is a chockfull of trojans, viruses and other bad juju.

    Sunday, February 01, 2009

    ASP.Net – A Data driven Google Map example

    In a recent post, I had written about my data driven Virtual Earth map mashup example. In that example, I used the ASP.Net Virtual Earth server control, to display traffic camera locations that are stored in SQL Server database.

    The VE ASP.Net control makes it extremely easy to take data from a database table and display it on a map. And all of it can be done using server side code. The ASP.Net control allowed me to rapidly prototype the application.

    The one problem with the Virtual Earth ASP.Net control is that it cannot be used in a government website free of cost. On the other hand, Google Maps can be used in a public facing government website free of coast.

    This prompted me to look for a method for displaying data from a database in GoogleMaps.

    There are some ASP.Net controls available for working with GoogleMaps, but nothing that seems to be stable and free. In addition, I wanted to test out calling web-services using the AJAX toolkit from client java-script code. The idea is simple, the data is made available via a web-service. The web-service is consumed by calling it from client java-script. The data is then added to the Google Map layer and displayed. ASP.Net AJAX makes it extremely easy to call web-services from java-script, in addition, the data is made available as an object, allowing you to call properties and fields that were made available in the corresponding C# object in the server side code. After that using the data and adding it to Google Maps is normal java-script code.

    Here is the Denver traffic cameras map mashup created using Google Maps:


    I will post the code after cleaning it up some.

    Using Google Earth took me much more time than using the Virtual Earth ASP.Net control. This was mainly because I had to learn 3 new technologies to get the whole thing working (Web-services, Google Maps API and Javascript invocation of web-services). The next time I have to create such a mash-up, I am sure I will take much less time, but compared to using the VE ASP.Net control, using Google Maps in an ASP.Net data-driven web-page will definitely take more time.

    Update (03.25.2009): I have posted code for how to make a website like this as part of another post "Using Virtual Earth control with a Web-Service". The ideas used in that example are very similar to what I did for this Google based map-example. JavaScript on the client's machine calls a web-service, which returns map data in JSON format. The JavaScript then takes the data and adds the points to the map. If you look at the sample in that post, you should find it fairly easy to create a Google Map version of it.