SQL LocalDB vs SQL Server CE

2019-01-17 10:31发布

I have a small project that will have 1 user on 1 computer. The database will be rather small (probably less than 1 mb of data). I plan to use WPF and Entity Framework for that project.

I came up with 2 potential database solutions for my project : SQL Server CE and SQL Server Express LocalDB (with SQL Server 2012). I have never worked with any of those, I'm more used to work with the full SQL Server 2008 installation.

I also want it to be easy to install on the client. Ideally I'd like to just throw a bunch of files on a folder (along with my .exe file).

So anybody here could suggest me the best technology to use?

Thanks!

6条回答
虎瘦雄心在
2楼-- · 2019-01-17 11:03

Also, if hiding your intellectual property/schema/data from easy access by users is important, SQL CE can be password protected/encrypted. SQL Local db can be easily opened from management studio.

查看更多
冷血范
3楼-- · 2019-01-17 11:04

It depends, but based on your requirements (ie very small amount of data and XCopy installation), your only option is SQL Server Compact, as the footprint of SQL Compact on disk is about 18 MB vs 160 MB with LocalDB, and LocalDB requires an administrator install (comes as an MSI only) - but if SQL Server compatibilty is more important, LocalDB is the best choice (as marc_s notes)

查看更多
戒情不戒烟
4楼-- · 2019-01-17 11:14

Forgetting all the vague "it's easier", "it's smaller", "it lacks punch" or "it's lighter" answers (no offense), I think one should focus on the main difference between the two when faced with the choice:

  • LocalDB is out-of-process.
  • CE is in-process.

Running as part of the application process or not has many implications which probably should be explored in separate questions.

The most obvious one though is that if you need to access the database from multiple applications using an in-process DBMS (such as CE), all applications will access the database file directly using their own cpu-time. Synchronizing them is really hard, and realizing this helps understanding why CE has less features (that and many other things).

Also note that while one may worry that multiple processes running the same CE code might take up more memory than necessary, remember that the operating system is smart enough to share pages from its page cache between multiple processes, so that one is really not an issue.

LocalDb is simply a way of managing a normal Express instance automatically, and on a per-user basis (it's not different from SQL Server Express, it's the same thing).

查看更多
叛逆
5楼-- · 2019-01-17 11:15

See this page for some background behind why LocalDB was created

It was created specifically for developers. It is easy to install, requires no management, yet compatible with other SQL Server editions at the API level. In this regard it is like a lightweight version of the free SQL Server Express edition.

While this seems similar to SQL Server Compact, there are differences:

  • Execution mode: SQL Server Compact is an in-proc DLL, while LocalDB runs as a separate process.
  • Disk usage: all SQL Server Compact binaries amount to some 4MBs, while LocalDB installation takes 140MBs.
  • Features: SQL Server Compact offers core RDBMS functionality like querying, while LocalDB provides a much richer set of features, including Stored Procedures, Geometry and Geography data types, etc.

The way I see it, LocalDB is often used for offline development to ensure that the code you develop is 100% compatible with your production SQL Server database.

查看更多
不美不萌又怎样
6楼-- · 2019-01-17 11:18

See the Introducing SQL Server Express Local DB Runtime presentation - gives a great overview.

The huge benefit of LocalDB is that it's real SQL Server - it's a special version of SQL Server Express, but it basically supports everything that "real" SQL Server has - spatial data types, stored procedures - you name it.

SQL Server Compact Edition on the other hand is a very much scaled down version - lot of features and datatypes aren't supported. It's smaller and more "agile" - but it lacks a lot of punch.

I personally would pick SQL Server Express with the LocalDB runtime over SQL Server CE 4 - unless you specifically need the tiny size of SQL Server CE (e.g. on a mobile device).

Also see a comparison between SQL Server CE 3.5, CE 4.0, SQL Server Express 2008 R2 and SQL Server 2012 Express LocalDB on ErikEJ's excellent Everything SQL Server Compact web site.

查看更多
Evening l夕情丶
7楼-- · 2019-01-17 11:22

I'm really going to have t go with ErikEJ here. I don't have the reputation to vote up his answer, but given your requested target SQL CE is really the quickest in and out. Many of the comparison issues given link provided by marc_s on SQL CE's "missing features" VS LocalDB are mitigated by virtue of your using EntityFramework (Procedural T-SQL is not supported, but if you use EF and Lambda and LINQ, that won't really be an issue).

查看更多
登录 后发表回答