Formatting dtsConfig Files

If you write dtsx in SQL Server 2005, often (if not always) you have to make them configurable, in particular if you need to deploy them in various environments (dev, test, staging and production).

Natively the SSMS produces a single-line xml file, so not very readable, but there is a little trick to format them automatically:

  1. open the dtsConfig file
  2. in the editor, right click and "View Data Grid"
  3. expand the grid and make a small modification of a value (for example, add and delete a space)
  4. save the file

Converting Hyper-V Machines

In the past days I've downloaded a virtual machine from Microsoft called Information Worker Demo (now it's downloadable from the page 2010 Information Worker Demonstration and Evaluation Virtual Machine (SP1)).

It's very interesting because it contains:

  • Windows 2008 R2 Standard Edition x64, acting as a domain controller
  • SQL Server 2008 R2 Enterprise with Analysis, Notification and Reporting services installed
  • Visual Studio 2010 Professional
  • SharePoint 2010 Enterprise with FAST Search
  • Office 2010 with Visio and Project

After having downloaded a unrared it, I've got a problem: to run it, you need Windows 2008 R2 with Hyper-V role activated, or the free Hyper-V Server, because Windows 7 cannot run Hyper-V virtual machines.

After some (not easy!) searches on Google, I've finally found this fantastic tool: StarWind V2V Converter, which allows you to convert even Hyper-V machines without the need to run them!

Another (silly) problem: the password of the Administrator account is pass@word1, the keyboard is set to American, to to enter the "@" character... press Shift+2

Refresh in Entity Framework

Entity Framework by default caches the objects retured from the database.
This is convenient, for example, for pseudo-static reference tables, that rarely change and you can accept a restart of your application.

But more times you don't want this, this for example to data updated by multiple front-ends!
So, how can you disable Entity Framework caching?

The solution is:

var query = "some entity framework query"
Context.Refresh(RefreshMode.StoreWins, query);
IList<myEntity> myList = myQuery.ToList();

Having called the Context.Refresh(...) static method before ToList(), makes that the latter one handles correctly inserted and deleted entities, other than updated ones.

You can find a bit more details in the following question+answers page: How to refresh ObjectContext cache from db?.

SPSchedule.FromString

SharePoint 2007 allows you to define job definitions and schedule them, but you have to do it programmatically.

As it's impossible to change the job definition schedules from the UI, the preferred approach is:

  1. Define a feature that writes in the web.config the desired schedule
  2. Define a feature that schedules the job reading the desired schedule from the web.config

For second point, your friend is the SPSchedule.FromString static method, with returns an instace of a SPSchedule from a string that you can save in your web.config.
But how do you build this string?

You can refer to the definition of the method in the documentation page SPSchedule.FromString Method, that at the end of the page forwards you to the fantastic article SPSchedule.FromString(recurrenceValue) - syntax/format for recurrence value!

Visual Studio: Collapse All Solution Explorer

Sometimes you have to open very big solution files in Visual Studio; but when Visual Studio opens these big solutions, by default they are all expanded in the Solution Explorer window, so that you can see only a few projects, and you would like to collapse them all.

For this reason, I did some researches and found that Visual Studio hasn't a native command to do this, and so a dedicated macro is needed.

I found one in the post Collapse all Solution Explorer items in Visual Studio 2010: it is very good because the author comments how to install it also.

I've modified it, to ensure that the macro works after the project has been opened and you have worked in it, so that even if you expand projects and then collapse their parent nodes, the modified macro collapses all the projects correctly.

You can download the file modified by me in the file CollapseAllSolutionExplorer.vb.txt (I suggest you don't open it in your browser, but save it locally)

Configuring WCF Tracing

WCF is heavely based on configuration, so it isn't really easy to debug; logging can help developers in understanding what's happening: what calls are made, what exceptions are thrown, and so on.

To enable logging, you have to insert the following lines in the web.config file of the service application (often it's just your web-site):

<system.diagnostics>
  <trace autoflush="true" />
  <sources>
    <source name="System.ServiceModel"
      switchValue="Information, ActivityTracing"
      propagateActivity="true">
      <listeners>
        <add name="sdt"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="C:\Logs\Traces.svclog" />
      </listeners>
    </source>
  </sources>
</system.diagnostics>

Then you can open you *.svclog files with the Service Trace Viewer Tool, found in the local file SvcTraceViewer.exe

More details in the articles Service Trace Viewer Tool (SvcTraceViewer.exe) and Configuring Tracing.

Reading Nested Classes from Reflection

Sometimes you need to create instances of nested classes via reflection, so you need to read the type of the nested class from a configuration file, for example web.config.
So, what it its format?

The answer is: "MyNamespace.MyParentClass+MyChildClass, MyAssemblyName, Version=version, Culture=culture, PublicKeyToken=publicKeyToken"

Just a few notes:

  • In bold is the + separating the Namespace.ParentClass from the ChildClass
  • The assembly name doesn't contain the .dll file extension
  • An example of version is 1.0.0.0 and an example of culture is neutral

Installing ClearCase Remote Client for Visual Studio 2008 and 2010

Here is the guide to install ClearCase Remote Client 7.0.1 for Visual Studio 2008.

  1. If Visual Studio 2005 wasn't already installed, you have to create in the registry, under the node HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0, a string with name InstallDir and value the install path of Visual Studio 2008, tipically C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE.
  2. After that, install the client, downloaded from https://YourCCRCServer/ccrc/update/ccrcvsi_win32.zip
  3. Download the updates to the registrations specific for Visual Studio 2008 from ftp://ftp.software.ibm.com/software/rational/clearcase/7.0.1/VS2008_support/CC-CQ-VS2008.zip for 32 bit and from ftp://ftp.software.ibm.com/software/rational/clearcase/7.0.1/VS2008_support/CC-CQ-64_BIT-VS2008.rar for 64 bit.
    Extract the zip file, open with Notepad the file reg_VS2008.bat and change the initial assignements so that CC_for_VS=0 and CQ_for_VS=0 (but keep CCRC_for_VS=1).
  4. From the command prompt, go the folder with the extracted files and execute the file reg_VS2008.bat.
    If all went fine, from Visual Studio 2008 the top menu ClearCase should appear.

And here are the adjustments necessary for Visual Studio 2010.

  1. Download and extract the file from ftp://ftp.software.ibm.com/software/rational/clearcase/7.0.1/VS2010_support/CC_7.0.1_VS2010.zip.
  2. Modify the reg_VS2010.bat file so that CC_for_VS=0 and CQ_for_VS=0 (keep CCRC_for_VS=1).
  3. From the command prompt, go to the folder with the extracted files and execute the file reg_VS2010.bat.
    If all went fine, from Visual Studio 2010 the to menu ClearCase should appear.