maandag 15 november 2010

Windows CE change screen orientation

You can use

Microsoft.WindowsCE.Forms.SystemSettings.ScreenOrientation = Microsoft.WindowsCE.Forms.ScreenOrientation.Angle180;

to turn the screen 180 degrees.

Using

Microsoft.WindowsCE.Forms.SystemSettings.ScreenOrientation = Microsoft.WindowsCE.Forms.ScreenOrientation.Angle0;

you can restore the default orientation

vrijdag 27 augustus 2010

Detect .Net framework version with your browser

Internet explorer sends out information about what .Net version is installed on your machine.
Scott Hanselman created a nice website that extracts this information, displays it and presents available updates for your machine (if needed): www.smallestdotnet.com

dinsdag 24 augustus 2010

Upgrading a Sql Server Compact database file

Recently I upgraded my project from Sql Server Compact 3.0x to Sql Server Compact 3.5 (I was already using VS 2008, but with SQL Server Compact 3.0x that comes with VS 2005). You can do this easily by changing the System.Data.SqlServerCe reference in your project to the new 3.5 dll.

But when you try to run the project using an existing Compact database, you get the following exception: 
"The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method."

image

You can indeed upgrade the file using the code as indicated in the exception message (SqlCeEngine.Upgrade()). But because I’m always deploying the application with a ‘ready-to-start’ sdf file, I only need to do the upgrade once. Therefore I decided to use Sql Server Management Studio 2008 to upgrade the file for me.

You can use following steps to upgrade:
1) Open Sql Server Management Studio 2008 and choose ‘Sql Server Compact Edition’
image 
2) Choose ‘Browse for more’ in the ‘database file’ combo box; an explorer window will open and you can browse to your sdf file.
3) Management Studio will detect that the file was created in a previous Sql Server Compact version and displays a warning message (which basically says the same as the .net exception):
image
4) When you press OK here, Management Studio converts the file for you. You can now run your program again, using the upgraded sdf file.

maandag 23 augustus 2010

Entity Framework: ‘does not support datatype datetime2’

While testing on my local development machine, I use a SQL Server 2008 instance. I generated the EF model using that same local database and everything works fine. After the testing period, I wanted to run the same tests on a production server.
The moment I tried to update an entity containing a datetime field, I received the following exception message:

“The version of SQL Server in use does not support datatype 'datetime2'.”

image

After checking the ddl of the tables on both test and production database, I found no differences.
What was the problem (and solution)?

It turns out that the model generator puts some database targeting information in the generated model (the edmx file). Since my production database was still a SQL Server 2005 instance, using the model on that database gives runtime errors, because statements are generated that the SQL Server database doesn’t understand. The problem is here (in the edmx file):

image

The ‘ProviderManifestToken’ attribute indicates that a SQL Server 2008 database was targeted. When you change this to ‘2005’ everything works fine again (even when you are connecting to the SQL Server 2008 database).

maandag 2 augustus 2010

Binding a Brush property to a Color

When you try to bind a Color directly to a Brush property, you get the following error in your Visual Studio output window:

System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value '#FFFF00FF' (type 'System.Windows.Media.Color'); BindingExpression: Path='LineColor' DataItem=LineVector' (HashCode=38524289); target element is 'System.Windows.Shapes.Line' (Name=''); target property is 'Stroke' (type 'System.Windows.Media.Brush').. System.InvalidOperationException: Can't convert type System.Windows.Media.Color to type System.Windows.Media.Brush.
   at MS.Internal.Data.DefaultValueConverter.Create(Type sourceType, Type targetType, Boolean targetToSource)
   at MS.Internal.Data.DynamicValueConverter.EnsureConverter(Type sourceType, Type targetType)
   at MS.Internal.Data.DynamicValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
   at System.Windows.Data.BindingExpression.ConvertToTarget(Object value).

The solution is to first wrap the Color in a Brush:

<Line.Stroke>
      <SolidColorBrush Color="{Binding LineColor}"/>
</Line.Stroke>

maandag 12 juli 2010

Network analyzer

To do some tracing of WCF messages I was planning to use Ethereal, a network sniffing tool. I used this tool successfully a couple of years ago. While searching for the download, I discovered it’s now known under the name ‘Wireshark’: http://www.wireshark.org/

More details on the name change can be found here: http://www.wireshark.org/faq.html#q1.2

zondag 27 juni 2010

JavaZone 2010 Trailer

Although I'm a .Net developer, Java was my first love and I still love the Java community and what they stand for. I try to keep up with everything Java so I read quite a lot of Java blogs.
While reading the James Gosling blog I found this really nice video I wanted to share with you. It was created by the JavaZone people to promote this years JavaZone conference.

The JavaZone 2010 edition takes place in Norway on the 8th and 9th of September (More info on the event can be found here)

EDIT: The original movie was removed from Youtube, but can still be watched here: here

donderdag 10 juni 2010

Render html in a reportviewer textbox

Starting with Visual Studio 2010, the included Microsoft ReportViewer control (ReportViewer v10) supports the rendering of HTML inside a textbox. With this functionality, you can use multiple styles inside one textbox.

The supported text format tags you can use are the following: <B>, <I>, <U>, <S>.

The default behaviour the textbox uses is to render plain text, but it’s very easy to activate the html rendering on a specific textbox containing a placeholder:

  1. Starting situation: a textbox with placeholder
    Textbox with placeholder
    (You can easily add a placeholder by dragging it from the datasource window to a specific textbox)
  2. Select the placeholder by clicking on it
    Selected placeholder
  3. Right click the selected placeholder and select ‘Placeholder properties’.
    Rightclick placeholder
  4. A property window opens:
    Placeholder properties window
  5. In the general tab, switch the rendering to HTML:
    Render html
  6. Now save your report and the HTML text you pass to the placeholder will be rendered correctly.

More information on the supported html tags you can use and useful guidelines (and limitations of the html rendering inside a reporting services report) can be found here: http://msdn.microsoft.com/en-us/library/cc645967.aspx