SQL Server Compact Private Deployment tweaks

As a follow up to my previous post about Private Deployment (the concept that you can simply include the SQL Server Compact DLL files with your application as content, so to speak), I will show you a couple of tweaks that the .NET Framework enables.

Forcing an existing application to use the private DLL files

If you have an existing application, that is compiled against the centrally deployed DLL files, for example assembly version 3.5.1.0 or 4.0.0.0, you can force the application to use the private assembly version files instead (3.5.1.50 and 4.0.0.1), via an application configuration file. Lets take ExportSqlCe40.exe as an example. This application is complied against assembly version 4.0.0.0, so it will not work unless SQL Server Compact 4.0 runtime is centrally installed.

image

To force this application to use Private Deployment only, create a .config file named ExportSqlCe40.exe.config, with the following contents:

image

<?xml version="1.0" encoding="utf-8" ?>
<
configuration>
<
runtime>
<
assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<
dependentAssembly>
<
assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" />
<
bindingRedirect oldVersion="4.0.0.0" newVersion="4.0.0.1" />
</
dependentAssembly>
</
assemblyBinding>
</
runtime>
</
configuration>

If you run the application now, you will get this error:

image

Now copy all files from the C:Program FilesMicrosoft SQL Server Compact Editionv4.0Private folder to the folder where the Exportsqlce40.exe file resides:

image

Now the application runs, and uses only the private DLL files.

Isolating the SQL Server Compact runtime files in a separate folder

Continuing the sample above, to be neater, it would be nice to have the SQL Server Compact DLL files in a subfolder below the .exe file location. This can be done by moving the files to a separate folder, for example named SqlCe4. Now I have moved all the SQL Server Compact files and folders to that folder:

image

Now modify the .config file as follows:

<?xml version="1.0" encoding="utf-8" ?>
<
configuration>
<
runtime>
<
assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<
probing privatePath="SqlCe4"/>
<
dependentAssembly>
<
assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" />
<
bindingRedirect oldVersion="4.0.0.0" newVersion="4.0.0.1" />
</
dependentAssembly>
</
assemblyBinding>
</
runtime>
</
configuration>

Notice the Probing setting above, that has been added. Also notice that this comes before the bindingRedirect.

Hop you find this useful.

Write a Comment

Your email address will not be published. Required fields are marked *