Monthly Archives: September 2012

Free e-book: Programming Windows 8 Apps with HTML, CSS, and JavaScript

windows8-js-ebook-coverI mentioned earlier, that in June Microsoft released a free preview of Kraig Brockschmidt’s Programming Windows 8 Apps with HTML, CSS, and JavaScript book, which although had only 4 chapters, proved to be a valuable source for developers using JavaScript to create Metro style applications for Windows 8. Now MS Press published the second preview of this book with a total of 12 chapters. The new chapters are:

  • Chapter 5: Collections and Collection Controls
  • Chapter 6: Layout
  • Chapter 7: Commanding UI
  • Chapter 8: State, Settings, Files and Documents
  • Chapter 9: Input and Sensors
  • Chapter 10: Media
  • Chapter 11: Purposeful Animations
  • Chapter 12: Contracts

The first preview was 158 pages, the second 537, and when all 17 chapters of the book will be ready for the Build at the end of October, it will be heavy Mosolygó arc

You can download the second preview for free:

If you are not interested so deep in this topic, or you just start Windows 8 development, you may be interested in the Beginning Windows 8 Application Development from Wrox. In this book 70 pages are about JavaScript Windows 8 development, touching similar topics like the MS Press book, but specially for beginners. Although this book will be officially released only next week, you can preorder it from Amazon.


Technorati-címkék: ,,

Publishing a WCF service on IIS 8

WCF services don’t run on IIS 8 with the default configuration, because the webserver doesn’t know, how to handle incoming requests targeting .svc files. You can teach it in two steps:

1. Add a new MIME type:

Extension: .svc
MIME type: application/octet-stream



2. Add a new Managed HTTP Handler:

Request path: *.svc
Type: System.ServiceModel.Activation.HttpHandler
Name: svc-Integrated


That’s it!


Technorati-címkék: ,,

Installing .NET Framework 3.5 in Windows 8 and in Windows Server 2012

I was installing SQL Server 2012 on Windows Server 2012, and everything seemed perfect. Although checking the prerequisites completed successfully, the installer displayed a warning popup in the middle of the setup about the required but missing .NET Framework 3.5. Because the dialog had only an OK button, I could only hope that .NET 4.5 which comes with the OS will be suitable for SQL Server. It wasn’t, and the installation failed. And it turned out, that installing .NET Framework 3.5 is not so easy in these new operating systems.

In Windows 8 and in Windows Server 2012, the .NET Framework 3.5 is a so-called Feature on Demand. This means, that the metadata for the feature is included in Windows 8 and in Windows Server 2012, but the binaries and other files associated with the feature are not included. And if you want to install the feature, you have to supply the files.


Windows 8

In Windows 8 open the Programs and Features dialog. For me the easiest way to access this dialog is via the Windows+X admin menu:


Select .NET Framework 3.5 (includes .NET 2.0 and 3.0) then click OK. A little searching…


…and a question, whether you really want to download the files from Windows Update:


Maybe it’s just me, but I really miss the info about the size of the download, and the option to supply the files locally. So if you really want .NET 3.5, click Download files from Windows Update. A little downloading…


… then if you are not so lucky (like me), this error screen:


The Tell me how to solve this problem link is exceptionally useful, because it links to the KB2734782 Knowledge Base article (Error codes when you try to install the .NET Framework 3.5 in Windows 8 or in Windows Server 2012) which can really help. In my case the problem was that my computer is a domain member, and group policy centrally configures the Windows Update settings. As I couldn’t change the policy, I had no other option than installing the .NET Framework from command line. Luckily the installation files are on the Windows 8 installation media, and with this short command you can install it from there:

dism /online /enable-feature /featurename:NetFx3 /All /Source:D:\sources\sxs /LimitAccess

It completes in a few seconds, I guess it’s much faster, than from Windows Update:



Windows Server 2012

The command line installation using dism works perfectly on Windows Server 2012 too, because the installation files are available also on the server installation media. Ironically, on the server, you can complete the installation on the GUI as well. Just start the Add Roles and Features Wizard and select the .NET Framework 3.5 Features option (click for larger image):


After the Next, just try to read the endless warning message:


The message tries to warn you to click the Specify an alternate source path link at the bottom:


Then enter the path of the source files, like D:\Sources\SxS:


That’s it. After you finish the wizard, SQL Server 2012 installs without any issue.


Daily .NET quiz

What is the output of the following code:

using System;
using System.Collections.Generic;

public class Program
  static void Main()
    var funcs = new List<Func<string>>();
    var urls = new List<Uri>
      new Uri( "" ), 
      new Uri( "" )

    foreach( var u in urls )
      funcs.Add( () => u.ToString() );

    foreach( var f in funcs )
      Console.WriteLine( f() );

A little help from ReSharper:


As the warning says, this piece of code behaves differently if compiled with the C# 4.0 and the C# 5.0 compilers! Actually this is the only breaking change in C# 5.

The problem is not new (check Eric Lippert’s post from 2009), this piece of code is not mine. I borrowed it from Martin Doms’ blog, who started a daily quiz series about .NET, and this is Quiz #006. The series goes for 3 weeks now, and Martin touches really deep topics. Maybe one day you will meet these questions in a job interview, so I definitely recommend reading them 🙂

You can read the full series at .

Which question do you like most?


Technorati-címkék: ,

Publishing SQL Server on a non-default port

If you afraid of malicious users and malwares that target port 1433, you can publish your SQL Server on a different port.

First, start SQL Server Configuration Manager, then navigate to the SQL Server Network Configuration –> Protocols for [instance neve]> TCP/IP branch, and open the Properties dialog (click for the full image):


On the second, IP Addresses tab you can configure the IP addresses and ports your database server instance is listening, and for example you can move it to port 8765:


Obviously, you have to open this port on the firewall for inbound connection. If you don’t want to hardcode the port number into the firewall rules, you can create a firewall rule for the SQL process itself. Start Windows Firewall with Advanced Security then create a new Inbound Rule by clicking New Rule… on the right pane. Here’s the trick: create a rule for a Program, and not for a port:


Then specify the full path of the sqlservr.exe of your SQL Server instance:


There’s nothing new on next steps, just create the rule as usual.

But, if your server is listening on a non-default port, how will your clients know which port should they connect to? That’s the purpose of the SQL Browser Service, that can tell the clients the dynamic port numbers of the instances. However, if you publish your SQL  Browser Service, anyone could query the port numbers, so moving the instances to other ports wouldn’t make any sense. The only solution is to explicitly specify the port number during the connection. Note that the syntax is a bit special, you should use a comma, instead of the usual colon:


Specifying the port number seems inconvenient, however you have to do it only for remote connections. Behind the firewall you can freely run your SQL Browser Service, so applications (websites) running on the server will be able to find the right SQL instance without hardcoding the port number into their connection strings.


Technorati-címkék: ,

How to encrypt SQL TDS connections

If your SQL clients (for example developers’ SQL Management Studios) and SQL Servers are not really “close” to each other, you should encrypt the tabular data stream (TDS) channel with SSL.

First, you will need a valid certificate. It must be issued by a trusted third party and the FQDN on it must exactly match the name of the SQL Server. To make your life easier, don’t trick with DNS aliases and DNS suffixes.

Next, import the certificate to the Personal Certificates store of the Local Computer account. Start the Microsoft Management Console (mmc), add the Certificates snap-in and when asked, select the Computer account. Expand the Personal\Certificates branch, then you can find the Import… menu item in the All Tasks group of the context menu:


To make sure your SQL Server can use this certificate, select the certificate on the right pane, then click the All Tasks –> Manage Private Keys… menu item:


You will get a usual ACL editor dialog. Click Add and select the account that runs your SQL Server instance. If you use SQL Server 2012, it by default runs with a managed service account that you can reference as NT Service\MSSQL$instancename. After selecting the account grant Read permission to it (you don’t need Full control!):


Start SQL Server Configuration Managert and navigate to the SQL Server Network Configuration –> Protocols for [instance name] branch, then open the Properties dialog:


Click the second, Certificate tab and select the certificate from the list:


If you don’t see your certificate here, check the certificate’s validity, FQDN, name resolution and permissions.

On the first, Flags tab, you can enable Force Encryption to make sure that all clients encrypt the communication:


By forcing the encryption you enable only those clients, that specify Encrypt=True in the connection string. If the client is SQL Server Management Studio, you can enable encryption on the Connection Properties tab by checking the Encrypt connection checkbox:


You can verify the encryption by Wireshark, or you can query the properties of the active connections directly from SQL Server via the sys.dm_exec_connections dynamic management view. This query lists the most important connection properties:

SELECT session_id, net_transport, client_net_address, local_net_address, 
       local_tcp_port, auth_scheme, encrypt_option 
FROM sys.dm_exec_connections

You can sleep well, if you see TRUE in the encrypt_option column.


Technorati-címkék: ,,,

HTML5 MIME types on IIS 8

If you have a website that uses HTML5 file types, and you run the site on IIS 7/7.5, you have to manually add the special file extensions in the IIS MIME Types list to make sure the webserver allows the clients to access them. You can add something like this to your web.config:

  <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
  <mimeMap fileExtension=".m4v" mimeType="video/m4v" />
  <mimeMap fileExtension=".ogg" mimeType="video/ogg" />
  <mimeMap fileExtension=".ogv" mimeType="video/ogg" />
  <mimeMap fileExtension=".webm" mimeType="video/webm" />
  <mimeMap fileExtension=".oga" mimeType="audio/ogg" />
  <mimeMap fileExtension=".spx" mimeType="audio/ogg" />
  <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
  <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
  <remove fileExtension=".eot" />
  <mimeMap fileExtension=".eot" mimeType="application/" />
  <mimeMap fileExtension=".otf" mimeType="font/otf" />
  <mimeMap fileExtension=".woff" mimeType="font/x-woff" />

However, when you upgrade your server and move your site to IIS 8, then you’ll get a nice 500.19 Internal Server Error.


If you enable detailed error messages, you can see that the error is in the mimeMap section of the web.config file:

Cannot add duplicate collection entry of type ‘mimeMap’ with unique key attribute ‘fileExtension’ set to ‘.m4v’

The root of the problem is, that IIS 8 supports the most widely used MIME types out of the box, and they are registered at the server level, therefore all websites inherit them.

The solution is to get rid of the manual registration from your web.config file. In my case, I had to remove the following extensions:

mp4, m4v, m4a, ogv, oga, ogg, webm, spx, svg, svgz, otf, woff

Please don’t forget to update your installers and setup scripts!


Technorati-címkék: ,,