Ben McCormack
Ben McCormack

Reputation: 33078

Where can I find resources for setting up a Silverlight app that accesses sql server 2008 Express DB?

I am trying to set up a basic Silverlight application to run behind the firewall on my Windows XP machine with IIS 5.1. We have a MySQL server for production purposes, but I would like to set up SQL Server 2008 Express Edition on my Windows XP machine to host the database part of the application.

I'm completely new to a lot of .NET develoment but would like to find the resources to get started. I've checked out Silverlight.net/GetStarted/, but unless I missed something there, this step wasn't explicitly there.

Does anyone know where I could go to read about how to do this and maybe a simple walthrough of a sample Silverlight application written to access SQL Server 2008 Express?

Any suggestions and links would be much appreciated.

Upvotes: 1

Views: 126

Answers (1)

James Cadd
James Cadd

Reputation: 12216

There are 3 options that I know of for connecting to a database from Silverlight:

  • WCF: Create your own WCF service with methods like GetCustomers(), UpdateCustomers() and DeleteCustomers(). Those methods are implemented on the server side, so in the background you can use LINQ to SQL or just open an old-fashioned SqlConection and run some SqlCommands against the database.
  • ADO.NET Data Services: This is a custom WCF service implemented by MS. You point the service at an Entity Framework class (auto generated from your custom database, super easy to create) and in turn it'll accept standard http rest commands that that do things like GetCustomers/Update/Delete. You can then add a service reference to this guy from your Silverlight app and it will auto generate 1 class per table, etc along with a client to connect to the server (http port 80 so no firewall concerns here). On the client side you're interacting with rich classes that look just like your database structure and work well with LINQ. This is not Silverlight specific and could be used from any client, even a console app.
  • .NET RIA Services: This is like ADO.NET Data Services but adds support for many things Silverlight including property change notification on the client side (note that the bleeding edge CTP2 of ADO.NET Data Services also implements change notifications), easy to hook events for browser navigation (i.e. you get an event when the user clicks back or forward) and code sharing between the server and the client (just name your file MyClass.shared.cs in your ASP.NET application and it magically shows up in your Silverlight client).

All of these options use http port 80 so they'll work well with your firewall. I'd really encourage you to try all 3 if you've got the time. If you don't have the time go directly to ADO.NET Data Services (grab the CTP2 you'll appreciate the new features).

Plain vanilla SL + WCF + SQL, but it's a little old: http://msdn.microsoft.com/en-us/magazine/cc794260.aspx

Shawn Wildermuth's MSDN article is a good starting point for ADO.NET Data Services: http://msdn.microsoft.com/en-us/magazine/dvdarchive/cc794279.aspx

This will get you up and running with good results in short time but note that it uses beta software. You'll see how many improvements have been made to ADO.NET DS since Shawn wrote that previous article: http://blogs.msdn.com/astoriateam/archive/2009/09/01/introduction-to-data-binding-in-ctp2.aspx

And here's Brad Abram's mother of all data connectivity posts (RIA Services focus here - I think the series is up to 24 parts now): http://blogs.msdn.com/brada/archive/2009/08/02/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-summary.aspx

Upvotes: 2

Related Questions