Monday, March 11, 2013

Deploying your site with SQL CE 4.0 to shared webhosting

If you have a VPS or dedicated server, you got full access to it and normally shouldn’t run into any problems. But when you’re using shared webhosting, your actions are very limited. This post describes the errors you’ll most likely run into the first time you try this, and how to solve them.
You can either deploy from within Visual Studio or FTP the files to your host. If you hit the URL to your website, you’ll most likely get following configuration error with the according web.config fragment below:
Parser Error Message: Could not load file or assembly 'System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
You get this error because most providers don’t have SQL CE 4.0 assemblies installed (yet?). This means you’ll have to 'bin deploy' the assemblies together with your site. Visual Studio 2010 provides a "Add Deployable Dependencies..." context menu item, which let you choose to add the required assemblies for Razor or SQL Server Compact to the Bin folder.


With some 'luck' you hit the next error once you solved the problem above and refreshed the page:
Parser Error Message: Access to the database file is not allowed. [ 1884,File name = somepath\App_Data\YourDatabase.sdf,SeCreateFile ]
For this error you have to give read + write access to the App_Data folder, usually done in the File Manager of your hosting control panel. If you got this error on your private server, check if the service running the Application Pool (e.g. Network Service) has these rights on the folder. You will also have to add following line of code (e.g. in the global.asax file):
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
This is because, by default, SQL CE blocks access when the connection is opened under the ASP.NET networking process. Once I ran through these steps, I got everything up and running without any hiccups.

Source: http://www.bartlannoeye.be/blog/deploying-your-site-with-sql-ce-4.0-to-shared-webhosting-part-2

No comments:

Post a Comment