Getting Started with ASP.NET MVC - Part 6: ASP.NET MVC and Entity Framework
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.


Upload Image Close it
Select File

Browse by Tags · View All
BRH 6
#SQLSERVERCE 5
#SQL SERVER 2
SQL Server CE 2
#SQLCE 2
#TSQL 2
SQL Server 2
TSQL 2
SQLSERVER COMPACT 2
SQLSERVERCE 2

Archive · View All
August 2010 6

Access a local SQL Compact database from Silverlight 4

Aug 10 2010 4:02AM by Erik Ejlskov Jensen   

Thanks to the new COM support in Silverlight 4, it is now possible for an elevated OOB application to access a local SQL Compact database. Keep in mind that COM suppport only is available on the Windows platform, not on Mac.

And thanks to the excellent SilverlightCOM Toolkit on Codeplex, it is very easy to use the ADO COM objects from your Silverlight application in a familiar (.NET) manner. In addition to data access, the COM Toolkit also enables access to files and directories, including file contents, registry, environment and starting processes (for now).

In order to enable access to COM objects (on Windows platforms only, of course), the following properties must be set for your Silverlight 4 project (which becomes settings in the AppManifest.xaml file):

image_thumb5

 image_thumb8

UPDATE: Now updated for SL4 RTM, and hosted by me: http://www.freewebsite.dk/documents/1075668907TestPage.html#/About

Source code for the demo (only for 4.0 RC) is available here.

For the sample to compile with 4.0 RTM, changes as follows:

using System.Windows.Interop; 

change to:

using System.Runtime.InteropServices.Automation;

and change from:

ComAutomationFactory.CreateObject

to

AutomationFactory.CreateObject

In addition for the ComToolkit.Data class, changes  to the 3 files included in the .zip file below were required.

Zip

Install the Silverlight 4 runtime,  scroll down to the test application, right click it and select Install:

image_thumb11

You will get this security warning:

image_thumb13

Click Install to install and create shortcuts on your Desktop or  Start Menu.

This is the contents of the shortcut created:

"C:\Program Files\Microsoft Silverlight\sllauncher.exe" 2619253130.webite.se

The demo application will launch – change the connection string (which is an OLEDB connection string, not a .NET connection string) to use the SQL Compact OLEDB provider, and change the path to point to a SQL Compact file on your local disk:

Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=c:\install\projects\nwtest.sdf

image_thumb19

Change the SQL statement to a valid statement for your database:

SELECT * FROM [Employees]

Press Connect to open the connection to the database and then press Execute to run the query, and voilá, you are accessing a local SQL Compact database with Silverlight 4!:

image_thumb22

Republished with author's permission. See the original post here.

About the author

erik2

Erik Ejlskov Jensen, SQL Server [Compact] MVP, .NET and Windows Mobile Developer.
Erik has been using SQL Server Compact since version 1.0, and is a moderator of the SQL Server Compact MSDN Forum.
He looks forward to a bright future for SQL Server Compact 4.0, which can now be used with ASP.NET in addition to Windows Mobile and Windows desktop applications. See his  blog.

Tags: BRH, DOTNET, SQLSERVERCE, SQLSERVER COMPACT, #SILVERLIGHT, #SQLSERVERCE, SILVERLIGHT, #SQLSERVER,


Erik Ejlskov Jensen
224 · 1% · 145
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • This database also allows Silverlight 4 out of browser databases:

    Ninja Database Pro

    commented on Aug 24 2011 1:20PM  .  Report Abuse This post is not formatted correctly
    gfinzer
    2307 · 0% · 2

Your Comment


Sign Up or Login to post a comment.

    Copyright © Beyondrelational.com Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising