Operating System does not support the encryption mode provided

It is an error that can drive you MAD!

Recently, working with a client we had to call Microsoft in order to find out what this error message meant, and what the solution might be. I’m happy to say, it had nothing to do with the Operating System, the Encryption Mode or any kind of support. It turned out to be a SECURITY issue.

Here are the parameters: (we are doing some things a little weird, or at least, very niche so this won’t apply to everyone)

Running SqlCE 3.5 on a Windows 7 machine.
Running IIS 7 to serve pages on “localhost” from a website that resides locally, and a db that resides on the local machine.

Everyone knows that if you are going to access a SQL CE database from within a webpage, you need to call the:

  • AppDomain.CurrentDomain.SetData(“SQLServerCompactEditionUnderWebHosting”, true);
  • method.

    But our problem was that we could open the database from within an application yet, not from within the webpage. We had identical connection strings so that couldn’t be it.

    What was the solution? Easy. The application pool (“DefaultAppPool” for us) had an identity property set differently on the Windows 7 box than it did by default on the Vista box. We had to change it from ApplicationPoolIdentity to NetworkService and viola – success.

    It was like magic. Hopefully this entry helps you solve this problem if you suddenly find your self with Windows 7 machines out in the field that used to be able to access their Sql Ce databases and suddenly are not able to access it because of handled (or in our case, unhandled) exceptions.