Welcome to MSDN Blogs Sign in | Join | Help

Heading to Tech Ed US 08

It's that time of year again.  A quick note on some of the sessions/panel discussions I'll be presenting at, and some others that relate to SQL Server Compact.

Code

Session

DAT325
Wednesday 8:30AM-9:45AM

Unlocking the Power of Microsoft SQL Server Compact 3.5
With Visual Studio 2008, you can now embed SQL Server Compact as dlls directly within your application. But you've seen the intro talks; now what?  In this demo packed session, Ginny and Steve will dig into the more advanced scenarios for how to take advantage of SQL Server Compact within your applications. How to write managed Stored Procedures, sharing a common dll between desktop and device apps, using SQL Server Compact as a custom document format, tips on maximizing performance and how to deploy and version a local database within your app are all just some of the demos you'll see to maximize your end users productivity with Visual Studio 2008 and SQL Server Compact.

Location: S220 E

Presenters: Ginny Caughey and Steve Lasker

 

 

TEO Panel _24
Wednesday 1:00PM-2:00PM

Building Offline Enabled Applications Panel Discussion
In an online world, why are we building offline apps? Because networks are only occasionally available, or occasionally not available. However, building Offline apps is a bit more complicated. Come bring your thoughts to a panel of speakers that work on enabling offline apps from the storage, sync, programming model, and UI stack. The panelists will discuss what we're working on today, and what's coming in the future.

Location: Open Spaces on the main floor
Panelists: Steve Lasker, Ginny Caughey, Rob Tiffany, Liam Cavanagh, Glenn Block

 

 

TEO Panel _33
Friday 2:00PM-3:00PM

LINQ in the UI Layer
LINQ is commonly known as a great way to query data from external sources (databases, web services, XML, SharePoint, etc). However, there are numerous other places where LINQ can make the developers life much easier when working on the end user interface, especially when you incorporate DataSet into the mix. This panel will talk about these approaches and the possible pitfalls of using them.

Location: Open Spaces on the main floor
Panelists: Erick Thompson, Steve Lasker, Amanda Silver

 

 

MBL403

Building Custom Sync Providers for the Microsoft Sync Framework
Andy Wigley
Wednesday 2:45

 

 

WIN202 

Introduction to Microsoft Sync Framework
Liam Cavanagh
Thursday 1:00

 

 

MBL404

Microsoft SQL Server 2005 Compact Ultimate Performance Tuning
Darren Shaffer
Thursday 4:30

 

 

MBL07-TLC

Microsoft Synchronization Services for ADO.NET: From Desktops to Devices
Liam Cavanagh
Friday 8:30

 

 

MBL01-TLC

Taking Data Offline: Introduction to Microsoft Synchronization Services for ADO.NET
Liam Cavanagh
Friday 4:30

Road Trip

The week after Tech Ed Developers we'll be doing our next Road Trip.  We still have some time in a few of the cities, so if you've got something interesting, let me know and we might be able to swing by.

  • Tampa Florida, Monday-Tuesday, June 9th-10th
  • Los Angeles , Wednesday, June 10th
  • San Francisco, Friday, June 13th

PowerPoint Presentation

The following links were posted prior to Tech Ed. In typical fashion the content will continue to evolve until we actually present.  I'll leave a note here when these have been updated post the session.

Tech Ed US 08 DAT325 - Unlocking the Power of SQL Server Compact

The following demos were presented either as part of the Unlocking the Power of SQL Server Compact session Ginny and I gave, shown at the booth, or shown at other presentations for our June '08 Road Trip

Demos

We'll be spending a lot of time at the booth hearing from all of you that have started to work with Compact.  We continue to hear about cool scenarios, so come on by, and tell us what you like and what you think we need to do in our 4.0 release.

Thanks,
Steve

Posted by Steve.Lasker | 2 Comments

SQL Server Compact 3.5 SP1 Beta available

Developers looking to get the beta of SP1 for SQL Server Compact can download it from here:

If you install Visual Studio 2008 SP1 Beta, you'll get the Compact Sp1 as well.  But, if you need the Compact SP1 beta for Visual Studio 2005, or simply can't install the VS 2008 SP1 Beta for some reason, you can download the Compact beta directly.

So, what's in the Compact SP1 Beta?

  • ADO.NET Entity support for SQL Server Compact. In addition to runtime enhancements provided in the Compact runtime, you'll also get Designer support if you download the VS 2008 SP1 Beta.
  • Case Sensitive Collation support
  • Updates for datatypes exposed by SQL Server 2008 to be synchronized with Compact 3.5. We don't have any of these new datatypes in Compact, but sync will map them to equivalent types in Compact.
  • Bug fixes for several query optimizations
  • Additional overload to the SqlCeEngine.Verify() api to include additional consistency checking

Correction (May 15, '08):

The Verify overload was actually added just after SP1.  I forgot that I installed a later build when writing this post. ...so, it's coming, just not in the public SP1

 

System.Data.SqlServerCe.SqlCeEngine eng = new System.Data.SqlServerCe.SqlCeEngine();

eng.Verify(System.Data.SqlServerCe.VerifyOption.Enhanced);

Updates to the Sync Services for ADO.NET runtime, including the ability to leverage the SQL Server 2008 Change Tracking features in the SyncAdapterBuilder

What's not yet in the Beta?

  • Native 64bit support. This will be in the RTM download. It's just not part of the VS SP1 as we didn't ship the 64bit release with VS 2008, and we're trying to hold the rule that we only service bits that were already on the users machine.
  • A bump in our versioning to support private deployment and central deployment.
    • I'll describe this in another post, but essentially developers wanting to privately deploy Sp1 when RTM is installed will fail as both SP1 and RTM have the same version number. Since the GAC always wins, the newer, privately deployed dlls will not load. We've fixed this in a build just after the beta, so this will work when we ship...

When will it ship?
SQL Server Compact 3.5 SP1 will ship with Visual Studio 2008 SP1 and SQL Server 2008, which is scheduled for later this summer. 

Please post feedback and questions to SQL Server Compact 3.5 MSDN Forum and Synchronization Services for ADO.Net MSDN Forum

For bugs, please post to Microsoft Connect, and be sure to set the product name to SQL Server Compact Edition Repro steps are key.

Steve

Posted by Steve.Lasker | 1 Comments

Security and Encryption for SQL Server Compact

The nice thing about SQL Server Compact is the database can be treated as a document.  It's a single file, it's only "open" when being used and can use the standard set of security mechanisms that any other document can.  You can set ACLs on the files, and you can encrypt the file with the Windows Encrypted File System.

Any security expert worth their weight in "keys" will tell you security is a multi-layer process.  There's no "one master lock" you can use and be considered secure.  It's a layered approach. 

Here's a set of recommendations you can use for SQL Server Compact, but many of these will apply to any documents.

Use the Windows Encrypted File System
Encrypt the directory of all your "document", including the directory of your SQL Server Compact Data File

System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(System.Windows.Forms.Application.LocalUserAppDataPath);

dirInfo.Attributes = System.IO.FileAttributes.Encrypted;

This will flip the EFS flag.

Alternatively, you could simply set the Encrypted flag for just the Compact data file

using (SqlCeConnection conn = new SqlCeConnection(Properties.Settings.Default.LocalConnectionString)) {

    System.IO.File.Encrypt(conn.Database);

}

This will encrypt the data file, and the directory of documents to the specific user.  This means evil people can't simply map a drive and copy the file.  It also means evil people can't just steal the hard drive and log on as an administrator and copy the file.  There's some caveats here, and a full study of EFS is recommended, but that's a different conversation. 

What EFS doesn't do is secure the file while "in flight".  If you email the database, copy it to a USB key, copy it to a network share you must remove the EFS flag.  So now how do you protect the database while in flight?

Use the SQL Server Compact File Encryption
Within the SQL Server Compact Connection String you can tell the engine to encrypt the datafile with a password.  By simply specifying a password, the database is automatically encrypted.  We used to support an encrypt = true name/value pair, but it was sort of silly to have a password without encryption, and encryption without a password is about as useful as putting a lock on a door but leaving the key in the lock (on the outside of the door).  So, we no longer use this name/value pair and will likely throw an error  in a future release if the engine sees it.  Today Compact just ignores it.

To turn on Encryption, simply set the Password like the following:

Data Source=|DataDirectory|\Localdatabase.sdf;Password=Foo

What level of encryption do you want? 
That turns out to almost be a silly question as well.  Does anyone want a somewhat secure encryption algorithm?  Of course not.  But, the evil people keep cracking the encryption algorithms, and the older operating systems don't actually support the newer algorithms.  Laxmi posted the different versions supported here.  For 4.0 we'll do the latest and greatest at the time we release. 

To set the extra bit, simply specify the Encryption Mode like the following:

Data Source=|DataDirectory|\Localdatabase.sdf;Password=Foo;Encryption Mode=Engine Default

This may be needed when creating a database on the server, and streaming it to a PPC 2003 device, or Win2k which uses the same algos as PPC 2003.

In an upcoming updated post on deploying database with scripts, and versioning databases, I'll show how you can incorporate this into your "Health Check" api to assure newly created databases are encrypted.

Steve

 

SQL Server Compact 3.5 64bit coming soon in Sp1...

A while back I posted some info about our intention to ship a native 64bit release: SQL Server Compact and 64bit support discussing how developers that use Compact on 64bit machines needed to use WoW mode.

I'm happy to say our 64bit release is coming soon. We've actually been working on this for a while.  It's not as easy as it might seem. There were several issues to make this work that cover all our scenarios including:

  • Private Deployment - including the dlls directly within your project
    • Which also includes how to load a private version of 64bit when 32 is centrally installed, or the other way around
  • Opening a database from multiple processes
  • Sharing the same database across devices, desktops and servers

We originally hoped to get this done with 3.5 RTM last November, but with the added complications, we just needed some extra time.  Because SQL Server Compact supports multiple processes opening the same database, and we wanted to share the same file format across device, desktop, 32 and 64bit machines, we had a lot of extra work to do to make sure all those bytes aligned.  When working on 64bit operating systems, there was some extra work we needed to do to make sure 32 and 64bit machines could support the same file format and X-Process communications.  In addition to the scenarios where developers use Compact as a "document format" that can be emailed or posted to a sharepoint site, we know developers often pre-create the .sdf on the server, sync it, then stream it down to the client (device, 32 bit desktop, 64bit desktop).

Ease of deployment
When building your application, how many processor types do you need to build?  Should your users need to know whether they should have to install the 32 or 64bit versions?  Devs - maybe.  End users?  Why should they know or care.  To ease this model, we took on some extra work to make sure developers could build one version of their application, including both the 32bit and 64bit version of Compact directly within their application.  This means developers can build one version, their users install one version, and at runtime our System.Data.SqlServerCe.dll will automatically load the appropriate engine.

So, the good news is:

  • We use the exact same file format between device, 32bit desktop, 64bit desktop scenarios.
  • You can also open the same database from a 32bit process and 64bit process. For those that don't know, Visual Studio actually runs in WoW mode, even on 64bit machines.
  • You can build one version of your app, and your users can install one version and it will "just work"

The not so good news

  • RTM and SP1 will not work completely interchangeably. While we caught the file format issue early, we didn't catch the shared memory issue early enough to fix in RTM. We use shared memory to open the same database across two processes. So, this means if you have an application that uses Compact 3.5 RTM, and another that uses Compact 3.5 SP1 (64 bit), you won't be able to open the same file at the same time. The first one will win. If you simply update the RTM app to SP1, all will be good.

What 64bit platforms are supported
As a general rule, AMD64 is our supported 64bit clients, so that does mean we won't have the IA64bit release.  Do many of you actually use the Itanium server boxes?  If so, would they be needed for your "web servers" where you're likely to need SQL Server Compact?

When will it ship?
Our 64bit release will be available as a Web Download when we ship SQL Server Compact SP1.  This will align with the Visual Studio 2008 SP1 and SQL Server 2008 ship dates.  So, not very far out.

Will there be a beta?
With the tight timeframes, we didn't see a lot of value in doing a beta.  The reality is by the time we get the beta up, there's really no time for feedback.  There's actually a lot involved in shipping betas between EULAs and such.  If you really, really, really want to give it a try before we ship, we are doing external validation with a few key customers, so just send me a note and we'll see what we can do.

What components will be available?
As many of you know, we ship several components. 

  • Device
  • Desktop
  • Server Tools for Merge Replication

Of course we don't yet have 64bit devices, so nothing here.  But we will be shipping the desktop and server tools in AMD64 bit versions.

Native /Managed
Lastly, I figured I'd be proactive on a comment around the complexities of shipping native 64bit code, and how this is a bit more complicated for developers to privately deploy native code.  Today, we do ship SQL Server Compact as a native engine for our storage engine and query processor.  There are other components such as the Merge Replication Client and a few other libraries that are native as well.  While this does make privately deploying Compact a bit more difficult, there are some definite benefits in perf, scalability and stability.  We've heard this over and over again that a database must be reliable, fast and consume minimal memory or what good is it. Otherwise, why not use XML?  Today, the best way to do this is through native code.  How long that remains to be true is a question for another day, but be assured we're fully aware of the pros and cons to native and managed code and we are working with our friends in the CLR team to bring the .NET platform forward so it can perform even better for devices and support managed code in more and more interesting scenarios.

In the meantime, know that we're "on it", and it's coming soon.

Steve

 

 

 

 

Posted by Steve.Lasker | 7 Comments

SQL Server Compact Team Coming to your location… (Road Trip)

As part of our vNext release planning, we're heading out on the road to meet some of our customers.  With the assistance of Jon Box we did this a few weeks ago driving 1,400 miles around Arkansas and Tennessee and we had a blast.

Do you have an interesting usage pattern of SQL Server Compact?  Interested to host us for a few hours to tell us about it providing feedback on what we're considering for our next release? 

The 1-3 hr agenda sort of goes like this, with a 1/3 of the time allocated to each.  We're very flexible, and as long as we're talking to "developers", they've all gotten a lot of value from the meetings thus far.

  • Overview of how your using SQL Server Compact. What works well, what's doesn't.
  • We break into some Demos and conversations on what you could do today to make better use of Compact for any challenges you may be facing, but are already available within the product.
  • Feedback on what we're doing next. Based on the context setup earlier, are we fixing the right issues, enabling the right new scenarios, making your job easier so you could focus on the business tasks of the application?

When: We'll be in Florida for Tech Ed Developers.  We're looking to meet with customers the week of June 9th and will drive/fly to your location  Depending on where each company is located, we're mapping out our "road trip" accordingly. For this trip, we're staying within the US but will travel anyplace within the US.  We'll likely do a European road trip later this year around Tech Ed Europe.

If you're interested, please contact me here and we'll see what we can do to setup a meeting,

Thanks,

Steve

Posted by Steve.Lasker | 6 Comments

Sync Services for ADO.NET (Devices) CTP 1 Available for Download

They Sync team has just published a CTP release of Sync Services for ADO.NET on Devices.

This continues our commitment to deliver a consistent programming and sync story for all Microsoft clients using SQL Server Compact.  The download page includes a sample, and readme.

For feedback on the CTP: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1225&SiteID=1

Thanks and please let us know if this is the right bar for 1.0, what we must fixt before shipping, and what you'd like in V2,

Steve

Posted by Steve.Lasker | 7 Comments

C++ development will speed up with the use of SQL Server Compact

Jim Springfield, an Architect on the Visual C++ team has just posted a great example of how SQL Server Compact will be used to speed up search time during C++ development.  It's a great example of where traditionally databases were too overkill and in-memory processing with XML or custom collection management is  just too slow. 

What's great about this reference is nobody is more critical about perf than the C++ team. 

IntelliSense, Part 2 (The Future)

The feedback on Jims post are interesting as well. Once you have information in a queryable form, that's also fast, lots of interesting possibilities come up.

This is just one of the great examples where SQL Server Compact is being used.  Because Compact is embedded within the application code, you don’t even know it’s being used.  “It just works”.  There are many other teams at Microsoft using Compact, but can’t talk about all of them just yet.  It’s always great to hear about the great scenarios customers have, so if you’ve got a similar scenario, let us know.  We’re in the midst of our vNext planning, so the timing is perfect.

 

Steve

 

Posted by Steve.Lasker | 7 Comments

Stored Procedures and SQL Server Compact - the Great Debate

Much has been debated about the need for stored procedures within SQL Server Compact.  We often hear customers say, "Without stored procedures, how can you call yourself a real database".  Followed by: "Is this just a temporary situation, or will SQLce add sprocs in a future release?"  The simple answer is we don't intend to support stored procedures as an equivalent feature of our bigger brother, SQL Server.  Why, read on... 

If you really do want the exact features of the server on the client, than the beauty is Microsoft does have a product; SQL Server Express.  The thing to keep in mind is where do you prioritize your needs on the client?  Are you looking for developer simplicity so your developers can use the exact programming model of the server on the client?  Or do you need a consistent programming model across all clients from device to desktop?  Do you prioritize your end user experience for simplicity of deployment, configuration and overall working set?  With SQL Server Compact and SQL Server Express, Microsoft delivers a choice for where you want your consistency. 

  • SQL Server Express - consistency with the server programming model is the priority, with the assumption that deployment and working set are less of a concern. 
  • SQL Server Compact - consistency across all Microsoft clients with a focus on simplicity of deployment, and overall minimal working set.  A common subset of the server features are available, but full consistency isn't the concern, or priority.

SQL Server delivers from the smallest device, to the largest data center

Finding SQL Server Compacts Center of Value

At the heart of the issue is we target SQL Server Compact as the "compact" version of SQL Server.  SQL Server Compact (SQLce) uses a single file, code free format.  This makes SQLce one of the last code free, document formats. Every feature we do is gated on how it impacts our size, simplicity of deployment, code free, doc centric model and its ability to work across all Microsoft Clients (smallest devices on up to the desktop, and in some cases even the server).  SQLce is designed to support an individual's set of data and become part of the application.  It can take advantage of the Windows document security system. If we take advantage of these scoping requirements, we have the freedom to do some very interesting features, yet still remain compact so developers never have to think twice about including SQLce within their application.  Some of those features include the updateable, scrollable, databindable SqlCeResultSet, others include the private deployment model unique to SQLce and the doc centric model.

Simplicity of moving code from my central database to the client

The most popular reason developers ask for SQLce to support sprocs is so they can simply copy/paste their server data access layer code to the client or replace their MSDE/Express install with SQLce.  It's a fair, and on the surface seems a simple ask that would gain a huge advantage.  We all want to leverage the code we right, but how likely is it that your cached client has the same schema, or the same amount of data? It may only have some of the rows, some of the columns, or in some cases, may even de-normalize the database for client side simplicity.  On the server, we can assume endless resources, from data, to additional services. The client is typically meant to be an emissary to the application.  It's there to gather information, make the end user productive, but typically not meant to be the "authority" for all changes.  For a related blogicle, see: Empowering your users with reference data and knowledge

If we supported sprocs, how much do you want?

Let's just say SQLce supported stored procedures? Would you expect all the features of SQL Server to be supported?  SQL Server supports an extensive T-SQL syntax including intrinsic functions, types, DML, etc.  If we supported everything, SQLce would lose its primary goal of being compact and easy to deploy.  If we support a subset, what's the appropriate subset?  Is it just the set of query operations?  Seems like a logical place to draw the line.  If that's the case, do you really need stored procedures, or do you just need a central place to put your queries?

The Value of a Sproc

Before we go further into why we're not looking to add stored procedures, it helps to review the typical reasons developers and DBAs typically use stored procedures.  The table below captures some of the common requirements, and whether they typically apply to the local store.

Requirement

Applies to a local store

Abstraction - By placing all the queries in a sproc, developers and DBAs can maintain a "public contract", enabling changes to the underlying database, but maintaining the same query input parameters and returned result

X

For multi-user databases, this is an important feature as new applications that come online may require the underlying data model to change.  Sprocs give a great way to shield app2 from breaking app1.  On the client, do we need multiple application abstraction from a single database?  Or is the application and database coupled together on the client? 

Security - Certain applications/users are granted rights to groupings of sprocs.  These sprocs return only the information pertinent to that user.  Columns within the database, such as salary, commissions, etc., may never be exposed to the general user.

X

Multi-user databases require multi-level security models.  Each query could be from a different user, so different security models may apply.  In a local store scenario, the database is assumed to be the user's partition of data.  If the user doesn't require salary information, it's never brought to the client in the first pace. For columns that are required on the client for processing, but not directly exposed to the user, can the application provide security abstractions through its user interface for how the data can be viewed and modified?

Performance - By placing queries in sprocs, the database can "compile" them, locking in a query plan, making them optimized for the next execution

There are some definite benefits to "locking in" your query.  The reality is SQL Server has matured quite a bit, and no longer has the same benefits from caching stored procedures.  It's not that stored procedures got slower, but SQL Server got faster and smarter about building a plan.  The opposite can also be true.  There are many situations where a sproc locked in a query plan when there was a small amount of data in the source tables.  As the tables grew, the locked plan was wrong reducing the performance.  While a local store doesn't have nearly the same performance requirements, nobody likes a slow query, so we want to benefit from a caching solution.

Centralization of all T-SQL - DBAs like one place to go.  They don't need to cull through lots of developer code to find an offending query. 

Until the database can participate in compile time verification at all levels of performance, it will continue to be helpful to have one place to view, edit, tweak and tune any queries that apply to the database.  It's interesting to note that LINQ queries would likely follow this model as well.

Ability to incorporate business rules

Many DBAs and even developers sometimes attempt to use sprocs as their business layer.  With the SQL CLR one might assume SQL Server got even closer.  But combining the data layer and business layer can be one of the biggest bottlenecks to performance in an application.  Ironically, this is where SQLce can be easier to use. 

Does one size fit all?
While stored procedures may be over complicated for the client, it doesn't mean they shouldn't be used on the server.  Regardless of how you protect your central database, sprocs, views, services, any changes from any client should always be re-validated before applying them to the center of truth in your company. 

Layers of Complexity Justified by their Benefit

When making a cake for a party of 20, it's impractical to bake a single cake. Instead, the cake is baked in layers, with icing in-between each layer.  However, if all we wanted was an easy way to give our kids a treat in their lunch bag, the good old cupcake comes in handy.  Same batter, same icing, but I ‘m not sure it's practical to bake 5 separate 2" cakes and layer them with icing. 

On the server we can justify the multitude of layers because of the added complexity of requirements.  Tables have Views.  Views are exposed through sprocs.  Sprocs, Views and Tables have table and column level permissions.  On the server, we need to serve a multitude of applications.  We need to protect the corporate assets, and must be able to scale to thousands of concurrent users.  On the client, we don't have all these complex requirements.  All these layers become difficult to manage.  If the client were an exact mirror copy of the server, it might not be that bad, but as we discussed, that's just not the reality of most applications.  5 layer cupcakes are interesting, but not very economically practical.

Mapping the Server Requirements to the Client
In the table above, we discussed a few of the features do apply to the client, so how can we achieve these features with SQLce on the client?

Abstraction
Abstraction is essentially a way to encapsulate a set of SQL statements to isolate the underlying store from the programming model.  This can be easily obtained by using a common dll for data access to the database.  If we place the queries in a common Queries.dll, then 2 desktop applications and a device application can all share the same common data access layer.  This looks a lot like what we'd do anyway as it's a common practice to place all the ADO.NET Commands in a common Data Access Layer (DAL) dll.  The benefit here with SQLce is the same Queries.dll can be shared across devices and desktop as SQLce is consistently available across all Microsoft client environments.

What's the difference?
Assuming we did support sprocs within SQLce, we'd likely have some code similar to the following.  We'd have a method signature in our code that takes some parameters for our query, and in this case the type of ResultSet we should return.  Within the method we construct an ADO.NET Command object, and set the CommandText to the name of the stored procedure.  We'd then have to go to the database and create that stored procedure, and manage it separately.

public SqlCeResultSet GetCustomersByName(string customerName, ResultSetOptions resultSetOptions)
{
    SqlCeCommand cmd = new SqlCeCommand(
                    Sales.DataAccess.SQLQueries.CustomerGetByName,
                    GetConnection());
    // Pass the customerName parameter
    cmd.Parameters.Add("@companyName", customerName);
    cmd.Connection.Open();
    return cmd.ExecuteResultSet(resultSetOptions);
}

Centralization of all T-SQL
One notion of sprocs is that all their definitions are made in a single location.  There's no need to search through all the code to find queries that must be tuned.  Building on our abstraction layer, we can store all our T-SQL statements in a common location using the Resource designer introduced in Visual Studio 2005.  You might consider using the Settings Designer, however it's not available in device projects, so we'll use the Resource designer which is available across all project types.

I'll add a Resource named SQLQueries to a project named Sales.DataAccess I can add an entry named: CustomerSelectAll with a value that contains the following query:

SELECT CustomerID, CompanyName, ContactName,
       ContactTitle, Address, City, Region,
       PostalCode, Country, Phone, Fax
  FROM Customers

In the Queries dll I could use the following code to return a SqlCeResultSet.  This is just the same as our above sproc example, with the exception that we'll place the name of our strongly typed resource in the CommandText parameter.  We still have our queries as strings, but instead of them being placed within the database, we place them in the resources file of the project.  By using the code bolded below, we get a strongly typed reference to our named resource.  While we can't validate the query text at build time, we can validate that all our named resources are valid.  If we ever wanted to know if a query was being used, we could simply rename the query in the resource designer, do a build and find any broken references.  Not something we could do with sprocs as the CommandText is simply the name of the sproc.  Sure, you could put the sproc name in resource, but we're back to 5 layer cupcakes. 

There are other advantages to using the resources model as well.  If we were to place the query directly in the code below, we'd have to place it in quotes.  We'd likely get hung up with formatting, placing line wrappings with quotes all over the place.  Using the resource designer, we can simply copy/paste the query directly into SQL Server Management Studio to test the query, executing the show plan to understand how index are used.

public SqlCeResultSet GetAllCustomers(ResultSetOptions resultSetOptions)
{
    SqlCeCommand cmd = new SqlCeCommand(
        Sales.DataAccess.SQLQueries.CustomerSelectAll,
        GetConnection());
    cmd.Connection.Open();
    return cmd.ExecuteResultSet(resultSetOptions);
}

Of course this could be expanded to support parameters as well.  Assuming I only wanted customers given a CustomerName, within the Resource designer, I add another resource named CustomerGetByName, with the following query:

SELECT CustomerID, Company Name, ContactName,
       ContactTitle, Address, City, Region,
       PostalCode, Country, Phone, Fax
  FROM Customers
 WHERE CompanyName LIKE @companyName

I then add a method to my data access dll similar to the following:

public SqlCeResultSet GetCustomersByName(string customerName, ResultSetOptions resultSetOptions)

{
    SqlCeCommand cmd = new SqlCeCommand(
                    Sales.DataAccess.SQLQueries.CustomerGetByName,
                    GetConnection());
    // Pass the customerName parameter
    cmd.Parameters.Add("@companyName", customerName);
    cmd.Connection.Open();
    return cmd.ExecuteResultSet(resultSetOptions);
}

Turkey or Turducken: Ability to Incorporate Business Rules

Once you have access to the full framework, why would you limit your business rules to T-SQL?  Sure you could host the CLR within SQL Server, but then you're hitting some interesting scalability questions.  On the server, you're communicating with an external service.  With SQLce on the client, your hosting the database in-proc with your app. Placing business logic within the database could be viewed as a Turducken. With the above model of using a common data access dll, you can place your business logic within your managed sprocs, and still centrally manage the queries.  We'll just call this the classic stuffed turkey.

public int CustomerInsert(string customerID, string companyName, string contactName, string contactTitle, string address, string city, string region, string postalCode, string country, string phone, string fax)
{
  DataValidationErrorCollection dataValidationErrors = new DataValidationErrorCollection();
  if (companyName.Trim().Length == 0)
    dataValidationErrors.Add(new DataValidationErrorItem("CompanyName",
        companyName,
        "A value for CompanyName must be provided"));
  if (contactName.Trim().Length == 0)
    dataValidationErrors.Add(new DataValidationErrorItem("ContactName",
        contactName,
        "A value for ContactName must be provided"));
  if (phone.Trim().Length < 10)
    dataValidationErrors.Add(new DataValidationErrorItem("Phone",
        phone,
        "Phone numbers must be at least 10 digits long, including the area code"));
  if (dataValidationErrors.Count> 0)
    throw new DataChangeException(
      "Validation Errors when attempting to create a Customer row",
      dataValidationErrors); 
  using (SqlCeCommand cmd =
          new SqlCeCommand(DataAccess.SQLQueries.CustomerInsert,
                           GetConnection()))
    {
     cmd.Parameters.Add("@customerID", customerID);
    
cmd.Parameters.Add("@companyName", companyName);
    
cmd.Parameters.Add("@contactName", contactName);
    
cmd.Parameters.Add("@contactTitle", contactTitle);
     cmd.Parameters.Add("@address", address);
     cmd.Parameters.Add("@city", city);
     cmd.Parameters.Add("@region", region);
     cmd.Parameters.Add("@postalCode", postalCode);
     cmd.Parameters.Add("@country", country);
     cmd.Parameters.Add("@phone", phone);
     cmd.Parameters.Add("@fax", fax);
     cmd.Connection.Open();
     return cmd.ExecuteNonQuery();
    }
}

Security
For a local database, you have data on the client.  There are some interesting ways to secure that data, but the best security model is to limit your exposure in the first place.  Since we're typically using a local database to represent caches of data from one or more remote sources, the first security model is to leverage those sprocs on the server to only download the data relevant to the particular user.  With technologies like Sync Services for ADO.NET and the Sync Framework, you no longer need to worry about publications that must be replicated across all your clients.  You have a lot of flexibility to simply issue sync aware queries that can be sprocs, views, functions, or any other SQL Server construct that returns data.

Performance
A client database has a different performance profile than that of a server.  For any given application a number of queries are executed per second.  On the server, you have a number of queries per application multiplied by the number of users.  This means that the server has a multiplier of N x NumberOfUsers, so performance on the client is a subset.

The other pattern to recognize is the server requires a stateless environment in order to scale, while the client can benefit from maintaining open connections.  For SQLce, the first connection per database loads the engine, while SQL Server loads the engine upon service startup.  On the client we still want to benefit from cached query plans. SQL Server Compact caches its query plans per SqlCeCommand object. Since we're not typically trying to share a database across multiple applications, this model works well as the database doesn't bloat with cached plans.  On SQL Server, a significant amount of memory can be consumed by cached plans and data, not a problem on the server as it's typically dedicated to these sorts of loads, amortized across multiple clients.  On the client, we need to work within a more constrained memory model as the client memory is shared by the entire application, not just the data layer. It also needs to share with Outlook, PowerPoint, Media Player/Zune, IE, and all those other things running on your computer. So, we still benefit from cached plans, but in a slightly different model.

Summing it up
If we consider all the reasons developers and dba's like sprocs, the majority of these either don't apply to the client, or their simply managed a slightly different way.  There are lots of analogies here ranging from motorcycles and cars, to SUV's and Tractor Trailers.  You drive each of these with a base set of common concepts. Motorcycles have a throttle, clutch, brake and gears. You may have to learn the subtleties of how these apply to cars, trucks and motorcycles, but anyone that rides a motorcycle would tell you that a trying to use a steering wheel just would destroy the experience of the ride. Once you adjust to a few things, riding a bike enables a freedom like no other vehicle.  Likewise, if I was trying to move my family from New York to Redmond Washington, my motorcycle wouldn't be appropriate. 

Now, if I still haven't convinced you there are reasons to leverage both Compact and Express for their given tasks, than you can certainly use SQL Server Express as your local store.  But when we go out to dinner downtown, I'll probably just must meet you there as I'll assume you'll be driving a truck and will have a hard time finding a parking spot.

Steve

Posted by Steve.Lasker | 8 Comments

MSDN Webcast: Introducing SQL Server Compact 3.5

On Wednesday, Jan 16th '08 from 9am-10am PST time, I'll be doing an MSDN Live webcast covering an introduction to SQL Server Compact 3.5.  This will be my first public presentation of SQL Server Compact since we've shipped last November. 

Working at Microsoft is interesting.  Because of the ship cycles, by the time we've shipped the product, many of us have been working on the "next thing" for several months.  It will be great to finally show the product we actually shipped, and everyone can get started.

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032364882&Culture=en-US

This presentation will be mostly based on the SQL Server Compact presentation I gave at Tech Ed EMEA, so if you want to get a preview of the content, you can download the deck here:

Presentations & Demos from Tech Ed Barcelona 07

Powerpoint
Demos:
SQL Server Compact Deployment
Using SQLce under ASP.NET
Creating Database Schema In Code
Direct Data Access with the SqlCeResultSet
ISAM Data Access with the SqlCeResultSet
Database Viewer-Used for Security Demo
My Recipe - Using SQLce as a custom doc format

The Tech Ed content is based on 75 mins, so I'll be trimming this a bit, and leaving some time for Q&A.  I'm looking forward to hearing from all of you.  BTW, if you have some specific topics you'd like me to cover, I'm finalizing the content today for anyone that wants to submit some ideas.

Steve

Connectivity Cross Version Compatibility of Merge Replication and SQL Server Compact

 

We've been getting a lot of questions regarding mixing versions of SQL Server and SQL Server Compact for Merge Replication.  Laxmi wrote a very extensive post explaining all the details here.  As noted, this is for Merge, not Sync Services, but has lots of useful details.

http://blogs.msdn.com/sqlservercompact/archive/2007/12/19/connectivity-cross-version-compatibility-sql-server-compact-3-5.aspx

 Steve

Presentations & Demos from Tech Ed Barcelona 07

Another great year in Barcelona.  First I want to thank our database track owner, Gunther Beersaerts. Gunther works in Technical Sales, and as a side job, manages this enormous event.  It's a lot of work to deal with us pesky speakers that always make changes right up to the last minute. Gunther did an awesome job, as usual, and makes it really easy for us to get with our customers to validate we're building the right products.  Thanks Gunther.

Here's the sessions, powerpoints and demos I showed.  I'll take the warning that these demos were built with a pre-RTM version of Visual Studio.  So, they may not work with B2 as is, but RTM is just around the corner, and you can open the files in B2.

DAT316 Implementing Microsoft SQL Server Express Edition
SQL Server 2005 Express Edition is designed to replace MSDE 2000 and offers the scalability, functionality and security of SQL Server 2005 in a package appropriate for redistribution with applications. This session provides an overview of the integration between SQL Express and Visual Studio as well as the additional tools available in SQL Server Management Studio Express. The session demonstrates common mechanisms for deploying SQL Express with an application and well as how to address common issues found when deploying a database with an application. Finally, there will be an overview of the expected features included in SQL Server 2008 Express Edition.
Express Power Point
Demos:
Deploying Express with Scripts
Managing Data Files

DAT306 Optimizing Online, Enabling Offline with SQL Server Compact and Sync Services for ADO.NET
With Microsoft SQL Server Compact, developers can now easily cache data on the client in a compact, yet capable, transactional, queryable document-like database format. To maintain the cache, Sync Services for ADO.NET enables developers to easily cache data directly or over services using Windows Communication Foundation (WCF). Visual Studio codename "Orcas" delivers new integrated, developer-oriented sync designers making caching an easy task to increase user productivity, decrease the server workload, and simplify data access. In addition to caching, you can use Sync Services for ADO.NET to enable full offline scenarios as well. Find out what SQL Server Compact and Sync Services for ADO.NET have to offer for the "edge of the network" clients.
Powerpoint
Demos
SyncNTierWithWCF Sample
One size doesn't fit all
- Logical Queuing Sample

DAT305 Microsoft SQL Server 2005 Compact Edition in Action
Looking for a reliable local store you can easily deploy embedded within your application? Wanting to know what programming options are available today, and what's coming in Visual Studio 2008? In this session, Steve will demo the different data access models including DataSet, ResultSet, TableDirect and LINQ. Steve will also demo the different deployment options available for Microsoft SQL Server Compact so that you don't have to worry about putting the power of SQL Server Compact directly into your app.
Powerpoint
Demos:
SQL Server Compact Deployment
Using SQLce under ASP.NET
Creating Database Schema In Code
Direct Data Access with the SqlCeResultSet
ISAM Data Access with the SqlCeResultSet
Database Viewer-Used for Security Demo
My Recipe - Using SQLce as a custom doc format

Thanks for a great conference, and look forward to hearing from you,

Steve

Posted by Steve.Lasker | 5 Comments

Heading to Barcelona for Tech Ed ‘07

Heading back to Barcelona again.  Getting around is about as easy as New York City with the subway system. What a great city.

I'll be giving 3 talks this year, so it will be a busy week.  As I finish my decks and demos, I'll post them here for download as well.

In addition to the talks, we'll be hanging around the booth as booth babes.  Not sure I'll be doing the high heels, although I could certainly use them.

DAT316 Implementing Microsoft SQL Server Express Edition
SQL Server 2005 Express Edition is designed to replace MSDE 2000 and offers the scalability, functionality and security of SQL Server 2005 in a package appropriate for redistribution with applications. This session provides an overview of the integration between SQL Express and Visual Studio as well as the additional tools available in SQL Server Management Studio Express. The session demonstrates common mechanisms for deploying SQL Express with an application and well as how to address common issues found when deploying a database with an application. Finally, there will be an overview of the expected features included in SQL Server 2008 Express Edition.
Mon Nov 5 16:00 - 17:15 Room 123   

DAT306 Optimizing Online, Enabling Offline with SQL Server Compact and Sync Services for ADO.NET
With Microsoft SQL Server Compact, developers can now easily cache data on the client in a compact, yet capable, transactional, queryable document-like database format. To maintain the cache, Sync Services for ADO.NET enables developers to easily cache data directly or over services using Windows Communication Foundation (WCF). Visual Studio codename "Orcas" delivers new integrated, developer-oriented sync designers making caching an easy task to increase user productivity, decrease the server workload, and simplify data access. In addition to caching, you can use Sync Services for ADO.NET to enable full offline scenarios as well. Find out what SQL Server Compact and Sync Services for ADO.NET have to offer for the "edge of the network" clients.
Tue Nov 6 15:15 - 16:30 Room 115   

DAT305 Microsoft SQL Server 2005 Compact Edition in Action
Looking for a reliable local store you can easily deploy embedded within your application? Wanting to know what programming options are available today, and what's coming in Visual Studio 2008? In this session, Steve will demo the different data access models including DataSet, ResultSet, TableDirect and LINQ. Steve will also demo the different deployment options available for Microsoft SQL Server Compact so that you don't have to worry about putting the power of SQL Server Compact directly into your app.
Wed Nov 7 10:45 - 12:00 Room 131   

We'll be presenting our next wave of releases of the Sync Framework as well, so be sure to check out:

WIN202 Introduction to Microsoft Sync Framework - Synchronization Framework for Enabling Roaming, Offline, and Collaboration Across Devices, Services & Apps  
Philip Vaughn
In this session we will introduce Microsoft Sync Framework. Attendees will learn about the capabilities of the sync platform and see a demonstration of multi-master synchronization across devices and services. We will use this demonstration to guide our walk through of the key components involved in building an application using Microsoft Sync Framework. Finally we will provide a glimpse into upcoming Microsoft products which will ship with out of the box support for Microsoft Sync Framework.  
Tue Nov 6 10:45 - 12:00 Room 114

WIN307 Implementing Solutions that Leverage Microsoft Sync Framework to Provide Synchronization Capabilities Across Devices, Services and Applications
Neil Padgett 
This session will focus on the steps a developer needs to take to incorporate synchronization into their application or services. First we will demonstrate how an existing line of business application can easily add synchronization support to allow users to work offline. Next we will describe the steps involved in building a service which exposes synchronization over SSE using Microsoft Sync Framework. We will briefly describe how support for Microsoft Sync Framework has been added for applications or services using file system or Microsoft SQL Server.
Tue Nov 6 15:15 - 16:30 Room 121   

DAT317 Replication Best Practices and What's New in SQL Server 2008  
Philip Vaughn
This session explores improvements that have been made in the replication space for SQL Server 2008 including the Peer-to-Peer Topology Viewer, Peer-to-Peer conflict detection, Replication Monitor usability improvements and more. This session will also cover many of the best practices associated with implementing large, robust replication topologies.  
Fri Nov 9 09:00 - 10:15 Room 114

DAT314 The Future of Sync Services for ADO.NET: Better on SQL Server 2008 and the Peer to Peer Provider  
Philip Vaughn
This session will focus on the enhancements being made to Sync Services for ADO.NET. First, we will discuss how Sync Services for ADO.NET is being integrated with SQL Server Change Tracking to increase developer productivity by providing integrated change tracking and conflict detection and subsequently decreasing the barrier to entry associated with implementing 2-way synchronization. In addition, this session will discuss the performance gains associated with leveraging change tracking to support scenarios with a large number of client nodes. Finally, this session will discuss how Sync Services for ADO.NET has been built on top of the sync platform currently referred to as Microsoft Sync Framework. Among other things, this platform has allowed us to extend Sync Services for ADO.NET beyond the traditional hub-spoke topology to support peer-to-peer synchronization.   
 Fri Nov 9 13:30 - 14:45 Room 125

Lastly, we'll be doing some a panel talk.  I expect this to be a flat out free for all, so it should be a lot of fun.

DAT01-IS Tell Us Where it Hurts! SQL Server Product Feedback Discussion  
Sethu Kalavakur , Steve Lasker , Carl Perry , Cristian Petculescu , Michael Rys
SQL Server 2005 has great new developer functionality but we need you to tell us what we're missing. What are your pain-points as a developer and the scenarios that go with them? We may make some suggestions as to alternatives and workarounds, but primarily we'll take your feedback back to the SQL Server product group for analysis. After all, it is customer feedback that is the primary driver for getting new features into future versions of SQL Server. If you can't attend, please provide your feedback on SQL Server via the http://connect.microsoft.com/sqlserver site.  
Thu Nov 8 17:30 - 18:45 Room 133

Looking forward to a fun week,

Steve

Posted by Steve.Lasker | 0 Comments

SQL Server Compact 3.5 Features

Ambrish, one of our great Program Managers for SQL Server Compact has posted some details on the 3.5 enhancements:

http://blogs.msdn.com/sqlservercompact/archive/2007/08/30/sql-server-compact-3-5-beta-2-downloads.aspx?CommentPosted=true#commentmessage

Steve

Posted by Steve.Lasker | 7 Comments

DevConnections Does Data

DevConnections, coming November 5-7, is just around the corner. Maybe you want to gamble a little, or see what strange things Carrot Top may be doing lately. But while you there; don't forget to checkout some of the data access track presentations.

A Data Access Track -hmmm
Recognizing that regardless of what technology you may use at the top of your app, Windows Forms, .NET Compact Framework, WPF, SharePoint, WCF, ASP.NET, TLA#42, you still likely have data underneath. Since data is data regardless of the top stack, this year Shirley has added a Data Access Track organized by non other than Julia Lerman.

With a Microsoft day track dedicated to data developers and another dedicated to DBA's, you should find everything you need to know. There will be presentations from Microsoft explaining how we think you'll use the new technologies coming in 2008 and the industry experts explaining how things work in the real world.

Connection attendees will be among the first to get a full working copy of Visual Studio 2008. That alone can pay the price for attending. 

We're also working on a special CoDe Focus on Data magazine that all attendees will receive.

Steve

Posted by Steve.Lasker | 1 Comments

Sync Services forADO.NET and SQL Server Compact Presentation

At Tech Ed US '07, and several other events I've been giving a presentation discussing how Sync Services for ADO.NET and SQL Server Compact can optimize online and enable offline scenarios. I've been hoping to do more of a write up/blogicle, but just haven't had the time. So, rather than continue to procrastinate, here's the deck I've been using.

Tech Ed US '07 DAT 325- Synchronization Options for SQL Server Compact

Tech Ed US '07 DAT 326- Microsoft SQL Server 2005 Compact Edition in Action 

A slightly newer, modified version of Sync Services without Tech Ed specifics
Optimizing Online, Enabling Offline with SQL Server Compact and Sync Services for ADO.NET

One size doesn't fit all - Logical Queuing Demo

In order to show how Sync Services may fit into an overall architecture, I've been showing this demo that I call logical queuing. As I have time, I'll write up an article explaining the concept, but here's a quick picture from the PowerPoint above.

Many developers looking to implement service queuing may take the following approach caching the operating they wish to commit on the back end. If the "service" isn't available, the developer queues the "message" in some blob, potentially MSMQ, a queued WCF channel, or something else.

In Logical Queuing, you save the raw data for the operation you wish to commit, but store it in it's original format marking it "good to go". Until you can actually send the operation, you can continue to edit it, query it, etc.

The save and send operations are split. It's the same code, but instead of the save operation creating the message which is then queued, the save operation saves the original data, and marks it "good to go". As the service becomes available, an event is raised which triggers the same code in the service queuing that would take the operational change and it then submits it to the service. It then marks the local data as sent awaiting some sort of confirmation from the server that it has been received, processed, declined, etc.

 

The point is several technologies may play together to fill the broader need of synchronizing reference data and interacting with existing or new services.

For those that haven't seen me present this, it may seem like hogwash, or overly complicated. I promise to have a screencast, and article to follow it up in the near future.

 Steve

Posted by Steve.Lasker | 5 Comments
More Posts Next page »
 
Page view tracker