Data Access Application Block Supports SQL Server Compact Edition with SqlCeDatabase Class - Enterprise Library 3.0 Tutorials

Data Access Application Block Supports SQL Server Compact Edition with SqlCeDatabase Class - Enterprise Library 3.0 Tutorials

by David Hayden ( Sarasota Florida ASP.NET C# SQL Server Developer ), Filed: Enterprise Library 3.0 Tutorials

 

I mentioned the release of the SQL Server 2005 Compact Edition RC1 a few weeks ago:

which gives us a light weight, in process relational database solution for applications that can be developed and deployed on desktop as well as on mobile devices.

Enterprise Library 3.0 DAAB has a new database class, called SqlCeDatabase, that provides direct support for it. The class sits in its own assembly, called

  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.dll

so you will need to reference the new assembly in addition to the 3 other assemblies you normally have done in the past:

  • Microsoft.Practices.EnterpriseLibrary.Common.dll
  • Microsoft.Practices.EnterpriseLibrary.Data.dll
  • Microsoft.Practices.ObjectBuilder.dll

A few things particular to SQL Server Compact Edition that I read in the notes and source code are:

  • Sql Server CE requires full trust to run, so it cannot be used in partial trust environments.
  • Because Sql Server CE has no connection pooling and the cost of opening the initial connection is high, this class implements a simple connection pool.
  • Sql Server CE provides a new type of data reader, called SqlCeResultSet, that provides new abilities and better performance over a standard reader.

 

SqlCeDatabase Class Example

Here is a quick example of using the SqlCeDatabase Class to check if a Subscribers Table exists in the database and get a count of subscribers.

 

string db =
@"Data Source=D:\junk\SqlCe\SqlCe\bin\Debug\Test.sdf;
Password=mypassword9999$
"; SqlCeDatabase database = new SqlCeDatabase(db); int count; bool tableExists = database.TableExists("Subscribers"); if (tableExists) count = (int)database.ExecuteScalarSql(
"Select Count(SubscriberId) FROM Subscribers");

 

Conclusion

I will talk more about the SqlCeDatabase Class in the Enterprise Library 3.0 Data Access Application Block to support SQL Server Compact Edition in the near future. Here I just wanted to provide an introduction.

 

New Feed: David Hayden ( Sarasota Florida ASP.NET C# SQL Server Developer )

Filed: Enterprise Library 3.0 Tutorials

posted on Tuesday, January 02, 2007 11:25 AM

My Links

Post Categories

Article Categories

Archives

Loose-Leaf Tea