Deploying SQL CE 4.0 in a Hosted Environment

by Doug 11. July 2011 19:32



Ok, not any "Hosted Environment" but specifically the hosting environment over at www.discountasp.net. If your app is hosted elsewhere, you still might be interested in this. The steps may be similar with your hosting company as well.

Note: As of this blog posting SQL CE 4.0 has been released to the public for 6 months - since January 2011.

Truthfully, I'm not much of an expert on SQL CE. (Compact Edition). The little I know is just the fact that it's embedded inside devices other than traditional computers to handle data duties using a schema and query language based on it's biggest brother: SQL Server. Because it's free from needing to run inside its own service or on its own machine, means that you can run it right along side all your code inside a phone, printer, mp3 player or other device.

However, with the release of the latest version (4.0), Microsoft added the ability of embedding it inside traditional web applications as well. CE has traditionally been a free Microsoft product and suddenly I was very interested in having a free & simple SQL database run in my web apps.

But I don't run my own web server, nor have a "Dedicated" hosting account. I have a shared hosting account that caters to ASP.NET web applications at DiscountASP.Net. If you're interested in a place to deploy your web apps, please visit them. ( www.discountasp.net) They are very good for many reasons. Including their support of CE.

( They don't have to support a free version SQL. They'd rather you pay for their offerings of the full version of SQL. But in reality, sometimes SQL Server is overkill. Sometimes you just need a bit of data, or a proof of concept, etc. So, kudos to them for understanding this from a developers point of view. )

The technical blog posts I was reading all had examples of CE deployment based on access to your own web server. Something got under my skin and had to chase down a process to see if I could make this work in my DiscountAsp.net hosted environment. I spent an afternoon fiddling with MSDeploy, Visual Studio 2010 Publish Settings and "My Account" settings at DiscountAsp.Net.

In the end: Success! After getting it running, I've been continually developing my app on top of it. And something else: Once deployed, you don't have to go through the entire process to upload small changes to your server. Simply use your favorite FTP program to punt new changes. That includes the SQL CE file (.sdf) too!

Remember that CE has serious limitations. No support for Functions. No support for Stored Procedures. It seems like it runs a little slow if you've got complicated queries. OK, well this all makes sense. Not much different than an XML blob wearing a SQL costume.

NOTE: Technical Evangelist Mark Wisecarver is working on a webcast based on these steps and will go into much more depth on the differences between SQL CE and SQL Server. Come 'on back for the link, it'll be [ here ] when the webcast is complete.

UPDATE: Mark has posted his Webcast HERE: http://www.dasptv.com/avc-view.aspx?videoid=39

For those of you who are pressed to carry on, here are the steps:


VIA DiscountASP.Net Control Panel

  • Login to your DiscountASP.net account
  • Go to IIS Tools
  • Go to MS IIS Manager Tab
  • Enable Primary Account User Access - (and click Update)
  • Click "Web Deployment Tool" (and click Update)
  • Go to Account Info/Edit
  • Note Server name (example web101)


VIA Visual Studio 2010

Download and install Microsoft SQL CE 4.0 here: http://www.microsoft.com/download/en/details.aspx?id=17876

  • File > New > Project > ASP.Net Web Application (Note: This is the template web app that comes with the ASPNETDB.MDF database already included - used for user login. Using the sequence listed here will NOT enable this .MDF database file to run on DiscountASP.Net servers - and the login feature of this template will not work using this database - it must use a regular sql server db)
  • In App_Data file, (this is where the .mdf db resides) Add > New Item > Sql Server Compact 4.0 Local Database

  • Add records to this database

  • Add connection string to web.config - Mine looks like :
    <add name="DataConnection" connectionString="Data Source=|DataDirectory|\Data.sdf" providerName="System.Data.SqlServerCe.4.0"/> Where |DataDirectory| will automatically be changed to "App_Data" upon using MSDeploy (later in this sequence)

  • Add some code to interact with the data on your default.aspx page

  • Run app locally to make sure it's doing what it's supposed to

  • Project > Add Deployable Dependencies (let VS go and add a bunch of folders with .dll files)

  • Project > Package/Publish Settings - your app properties pages opens defaulted to the Package/Publish Web tab

  • In the "Items to Deploy(Applies to All Deployment Methods)" section - set to: All files in this project

  • Check = Exclude generated debug symbols

  • unCheck = Exclude files from the App_Data Folder

  • In the "Items to Deploy(Web only) section - leave all boxes UnChecked

  • In the "Web Deployment Package Settings" section:

  • Check = "create deployment package as .zip file"

  • In the "IIS Web site/application name" section set to: Default Web Site/AppName (replace AppName with the name of your web application - no not change "Default Web Site")

  • Go to the Package/Publish SQL TAB

  • Click the "Import from Web.Config" button

  • Check the connection string that appears in the list - that goes with your SQL CE database

  • Use the Remove button to remove all other connection strings that you won't use on your deployed app (remember if the connection string to the ASPNETDB.MDF file is on the list, it must be removed. The login feature will not work using this mdf file on DASP servers...)

  • SAVE YOUR SETTINGS

  • Build > Publish (app Name)

  • The "Publish dialog shows up

  • Publish Method = Web Deploy

  • Service URL = https://[yourWebServerHere].discountasp.net:8172/MsDeploy.axd

  • Site/Application = yourdomain.com/yourAppName

  • Check = Mark as IIS Application on destination

  • Check = Leave extra files on server (Not sure if this makes any difference...)

  • Check = Allow untrusted certificate
  • Enter DASP UserName - the one you use to login to DiscountAsp.Net

  • Enter DASP Password - the one you use to login to DiscountASP.Net

  • Click Publish

  • Check the live version of your site.


So anyway, I've NOT tested this method over and over. But have deployed a simple app, it worked, then made changes to the code, re-deployed and the changes made it through the deployment process. Remember you can also FTP small changes once you've done the first successful deployment.


Let me know if this works for you!

Book Review: Pro Expression Blend 4 by Andrew Troelsen

by Doug 21. April 2011 19:35

 

 

Apress Publishing contacted me (along with others from the Microsoft development community) about reveiwing a new technical book by Andrew Troelsen.   Since I had the time, and was already familiar with the subject mattar (a program called Blend that is used to create web applications and more) I took them up on the offer.  I enjoyed the book, and I think the publisher and author will like my review which appears on Amazon.com, BarnsAndNoble.com and Slashdot.org and of course A Doug's Life:

 

 

 

 

Andrew Troelson has written a great book that breaks down Microsoft Expression Blend 4 into easy to understand  concepts.   Blend isn't necessarily a simple program to use.  This is the case for many programs that are used to create sophisticated applications. The programs used by developers (and designers!) are somewhat sophisticated as well.

 

 

Should you buy this book?  Absolutely - if you need to learn the Blend IDE. But you should really take a few moments to read the introduction.  Troelson's key point is clear: "This is Not a Programming Book, and Graphical Artists are Welcome!"  In other words, even though it's not a book that delves deep into programming,  .Net programming guru's will find this book very useful in getting up to speed with using Blend 4 as well as designers too.

 

 

In my first real world Silverlight projects I had used Blend 2 and 3, so moving through the book I felt right at home.  However there was much to learn about version 4 and some of it's capabilities that I'd never touched in my previous Silverlight projects.  I had never used custom control templates or custom UserControls.  Never tried a Windows Phone 7 project.  I have used SketchFlow - but discovered I wasn't using it to it's full potential.  

 

 

Following Troelson through the exercises is easy as everything is very clear. There are a generous  amount of color screen shots and the code samples (yes there is code  - but not too much) are in the same color format as when working in Blend code view.  I should say that his writing style is very casual.   Many technical books can make your eyes glaze while managing a heavy buzz kill of your excitement about learning the technology.  Troelson keeps things light and makes the technical point at the same time.

 

 

As well, there are lots of extra bits if info in the form of Notes (separated from the rest of the page content) and  detailed footnotes.  Troelson also provides a generous amount of links, references and images to help you follow up with subjects lightly touched upon, but are outside the scope of the book.

 

 

What I find exciting, is that once you develop some skills using Blend,  you can apply them to web applications (via Silverlight), Windows apps (via WPF) or mobile apps  (via Win Phone 7).  Having that kind of flexibility as a "deviner" (developer/designer) creates more value in learning Blend. 

 

 

I read the entire book, did all the exercises and tried much of the suggested extra stuff too. If you do the same, you will have worked with all the features of Blend 4 in one way or another.  Keep the book handy.  You'll probably take it off the shelf  during your next Silverlight, WPF or mobile Phone project.

 

 

 

Doug's Latest Tweets

Doug Who?

Hey, Doug here.  Thanks for visiting "A Doug's Life". 

 

I enjoy packaging my thoughts, pictures, video clips and other fragments into what hopefully makes up some interesting stuff to share.  

 

I've checked the list that gives you a better idea about me!

 

Love Web Technology
Sunday is for Pro Football
Hike or bike on trail most mornings
Halloween Rocks!
Chase the latest electronic gadgets
Married
(Happily Married)
Drama
Simplicity

 

My wife and I live in the shadow of Mt Lukens on the edge of the Angeles National Forest:

 

Tujunga, CA

More Stuff