I'm newbie in Silverlight world. I read number of articles to establish connection with SQL Server using Silverlight but sorry to say no one give me concrete results. I want to first make a connection with SQL Server database and then simply load data in combo box. Can anyone give any sound step wise example to make connection with Silverlight project. I found WCF service which is quite helpful to establish connection but feel difficulty to map this service. Please also suggest any other web service with WCF, thanks.
-
so you can connect to wcf service and not to a sql database? Or are you having problems calling the WCF service as well?Osama Javed– Osama Javed2013-04-06 06:24:23 +00:00Commented Apr 6, 2013 at 6:24
-
2As far as I know, Silverlight cannot directly connect to a database like SQL Server - it can only use services to get its data (like plain WCF or WCF RIA Services).marc_s– marc_s2013-04-06 06:41:07 +00:00Commented Apr 6, 2013 at 6:41
-
@OsamaJaved, I still dont know how to use WCF service to first make connection and then play with the data. It would be great if you explain with examplevitall– vitall2013-04-06 07:00:23 +00:00Commented Apr 6, 2013 at 7:00
-
Yes @marc_s you are right, after some RND on Silverlight connection, WCF play vital part to make db connectionvitall– vitall2013-04-06 07:03:05 +00:00Commented Apr 6, 2013 at 7:03
-
@vitall try this tutorial .. it solves the exact problem you are trying to solve. (dotnetcurry.com/ShowArticle.aspx?ID=228) . Essentially you need to create and host a WCF service . This service talks to the database and returns the required data. Your silverlight app then calls this Service to perform database access. Essentially you need to understand how WCF works. There are a bunch of tutorials on-line and honestly I cant explain these things half as well as these tutorials. I used pluralsight videos while i was working. I am not sure if they are free or not.Osama Javed– Osama Javed2013-04-06 10:17:09 +00:00Commented Apr 6, 2013 at 10:17
1 Answer
When you look at the Silverlight architecture, you'll see that the ".NET for Silverlight" runtime doesn't include any classes to directly access databases:
http://msdn.microsoft.com/en-us/library/bb404713%28v=vs.95%29.aspx

It contains service client classes, however - so you can use WCF (and WCF RIA Services) to fetch data from a remote server.
That approach makes a lot of sense, too - your Silverlight app will after all run on the client PC, typically in a browser - and you don't really want hundreds or thousands of client PC's anywhere over the planet to have direct access to your SQL Server database. Channelling these data requests through services makes a lot of sense in that way.
This is in contrast to ASP.NET where your code typically runs on the backend server infrastructure, so it's a lot "closer" to your database servers and can make direct calls to SQL Server - it then just returns HTML to the caller (the client's PC and browser).
I found this article here very informative and enlightening: