55

The application I want to build using MS Visual C# Express (I'm willing to upgrade to Standard if that becomes required) that needs a database.

I was all psyched about the SQL Server Compact - because I don't want the folks who would be installing my application on their computers to have to install the whole of SQL Server or something like that. I want this to be as easy as possible for the end user to install.

So I was all psyched until it seems that there are limitations to what I can do with the columns in my tables. I created a new database, created a table and when I went to create columns it seems that there isn't a "text" datatype - just something called "ntext" that seems to be limited to 255 characters. "int" seems to be limited to 4 (I wanted 11). And there doesn't seem to be an "auto_increment" feature.

Are these the real limitations I would have to live with? (Or is it because I'm using "Express" and not "Standard"). If these are the real limitations, what are my other database options that meet my requirements? (easy installation for user being the biggie - I'm assuming that my end user is just an average user of computers and if it's complicated would get frustrated with my application)

-Adeena

PS: I also want my database data to be encrypted to the end user. I don't want them to be able to access the database tables directly.

PPS. I did read: http://www.microsoft.com/Sqlserver/2005/en/us/compact.aspx and didn't see a discussion on these particular limitations

adeena
  • 4,027
  • 15
  • 40
  • 52
  • 1
    Did you see the part of my post where I mentioned that nText supports 500 million characters: not 255 ? – Joel Coehoorn Jan 03 '09 at 16:15
  • auto_increment is available... steps are edit table schema. choose column and then on the more options at bottom choose identity is true – webzy Feb 05 '16 at 10:11

9 Answers9

33

I'm not sure about encryption, but you'll probably find this link helpful:
http://msdn.microsoft.com/en-us/library/ms171955.aspx

As for the rest of it:
"Text" and "auto_increment" remind me of Access. SQL Server Compact is supposed to be upgrade compatible to the server editions of SQL Server, in that queries and tables used in your compact database should transfer to a full database without modification. With that in mind, you should first look at the SQL Server types and names rather than Access names: in this case namely varchar(max), bigint, and identity columns.

Unfortunately, you'll notice this fails with respect to varchar(max), because Compact Edition doesn't yet have the varchar(max) type. Hopefully they'll fix that soon. However, the ntext type you were looking at supports many more than 255 bytes: 230 in fact, which amounts to more than 500 million characters.

Finally, bigint uses 8 bytes for storage. You asked for 11. However, I think you may be confused here that the storage size indicates the number of decimal digits available. This is definitely NOT the case. 8 bytes of storage allows for values up to 264, which will accomodate many more than 11 digits. If you have that many items you probably want a server-class database anyway. If you really want to think in terms of digits, there is a numeric type provided as well.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Yes - I was thinking in terms of digits and I think the "int" stuff works. The text datatype limitations are really what I'm going to have the issue with - I need to store a potentially large amount of text (definitely more than 255 characters). I am now looking at the SQLLite that folks mentioned. – adeena Jan 02 '09 at 19:00
  • 3
    ntext support more than 500 million characters. I don't know where you got 255 from. – Joel Coehoorn Jan 02 '09 at 20:32
  • 1
    One of the biggest pains of CE is it can't run batched SQL scripts (e.g. multiple inserts in a script). It's completely crippled in comparison to SQLite – Chris S Mar 15 '13 at 16:03
17

A few, hopefully helpful comments:

1st - do not use SQLite unless you like having to have the entire database locked during writes (http://www.sqlite.org/faq.html#q6) and perhaps more importantly in a .Net application it is NOT thread safe or more to the point it must be recompiled to support threads (http://www.sqlite.org/faq.html#q6)

As an alternate for my current project I looked at Scimore DB (they have an embedded version with ADO.Net provider: http://www.scimore.com/products/embedded.aspx) but I needed to use LINQ To SQL as an O/RM so I had to use Sql Server CE.

The auto increment (if you are referring to automatic key incrementing) is what it always has been - example table:

-- Table Users

CREATE TABLE Tests (
    Id       **int IDENTITY(1,1) PRIMARY KEY NOT NULL,**
    TestName     nvarchar(100) NOT NULL,
    TimeStamp    datetime NOT NULL
)
GO

As far as the text size I think that was answered.

Here is a link to information on encryption from microsoft technet: (http://technet.microsoft.com/en-us/library/ms171955.aspx)

Hope this helps a bit....

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tab
  • 1,702
  • 2
  • 19
  • 39
  • 30
    Such a graceful comment - I misread the docs for the link I listed above - my mistake. A simple "perhaps you misread the docs" would have been cool... – Tab Apr 14 '09 at 19:36
  • 2
    Your answer is about "SQLite" but the question is about "SQL Server Compact" a.k.a. "SQL CE". – ChrisW Dec 18 '14 at 01:16
16

Had to chime in on two factors:

  1. I use Sql Compact a lot and its great for what it works for -- a single user, embedded, database, with a single file data store. It has all the SQL goodness and transactions. It hadles parallellism well enough for me. Notice that few of the naysayers on this page use the product regularly. Don't use it on a server, that's not what its for. Many of my customers don't even know the file is a "database", that is just an implementation issue.
  2. You want to encrypt the data from your users -- presumably so they can only view it from your program. This simply isn't going to happen. If your program can decrypt the data, then you have to store the key somewhere, and a sufficently dedicated attacker will find it, period.

You may be able to hide the key well enough that the effort to recover it isn't worth the value of the information. Windows has some neat machine and user local encryption routines to help. But if your design has a strong requirement that a user never find data you have hidden on their computer (but your program will) you need to redesign -- that guarentee simply cannot be accomplished.

John Melville
  • 3,613
  • 28
  • 30
  • Why "Don't use it on a server"? Can't/shouldn't it be used as the storage for an ASP.NET (web) application (i.e. used from a web server)? You do say that "It handles parallellism well" ...? – ChrisW Dec 18 '14 at 01:20
  • 1
    1. Perhaps I could have worded it better "don't use it to back a big website." That being said I had problems using SQL compact to back a little website on GoDaddy's cheap webhosting. My site got served out of multiple web front ends that all synced up to a shared file system. This lead to a pile of obscure concurrency bugs that only happened with load. Even though Microsoft now markets Sql CE for small websites, I have had better luck with the full SQL Server on the web. – John Melville Dec 19 '14 at 00:42
5

SQL CE is a puzzle to me. Did we really need yet another different SQL database platform? And it's the third in the last several years targeted at mobile platforms from MS ... I wouldn't have a lot of confidence that it will be the final one. It doesn't share much if any technology with SQL Server - it's a new one from scratch as far as I can tell.

I've tried it, and then been more successful with both SQLite and Codebase.

EDIT: Here is a list of the (many) differences.

dkretz
  • 37,399
  • 13
  • 80
  • 138
  • SQL CE had 3 name changes, otherwise, it's MS's only current mobile database engine. And it's reported to share a common API with SQL Server. – Anthony Mastrean Jan 02 '09 at 18:02
  • Note the link I added. I can't imagine how that list is congruent with a "common API", unless the few features it shares are invoked the same way - not very useful. – dkretz Jan 02 '09 at 20:50
  • The issue with other versions of SQL Server is that they have to be bought, or installed. If i'm building a media player, or a btc client, or an embroidery design software, my mother's not installing or managing SQL Server. The database *must* be completely transparent. – Ian Boyd Apr 10 '13 at 11:43
5

ntext supports very large text data (see MSDN - this is for Compact 4.0, but the same applies to 3.5 for the data types you are mentioning).

int is a numeric data type, so the size of 4 means 4 bytes/32 bits of storage (–2,147,483,648 to 2,147,483,647). If you intend to store 11 bytes of data in a single column, use the varbinary type with a size of 11.

Automatically incrementing columns in the SQL Server world are done using the IDENTITY keyword. This causes the value of the column to be automatically determined by SQL Server when inserting data into a row, preventing collisions with any other rows.

You can also set a password or encrypt the database when creating it in SQL Compact to prevent users from directly accessing your application. See Securing Databases on MSDN.

All of the items you mention above are not really limitations, so much as they are understanding how to use SQL Server.

Having said that, there are some limitations to SQL Compact.

  • No support for NVARCHAR(MAX)
    • NTEXT works just fine for this
  • No support for VIEWs or PROCEDUREs
    • This is what I see as the primary limitation
Travis
  • 2,654
  • 4
  • 26
  • 46
3

I've used the various SQL Server Compact editions on a few occasions, but only ever as data capture repositories on mobile platforms - where it works well for syncing with a server database, and with that sort of scenario is undoubtedly the optional choice.

However if you need something to do more than that and act as a primary database to your application then I'd suggest SQLLite is probably the better option, it's completely solid, widely supported and found in all sorts of places (used on the iPhone for example) but is surprisingly capable (The Virtual Reality simulator OpenSim uses it as it's default database) and there are lots of others (including Microsoft).

Cruachan
  • 15,733
  • 5
  • 59
  • 112
2

According to this post (http://www.nelsonpires.com/web-development/microsoft-webmatrix-the-dawn-of-a-new-era/) it says that because it uses a database file, only one process can access it for every read/write and as a result it needs exclusive access to the file, also it is limited to 256 connections and the whole file will most likely have to be loaded in memory. So SQL server compact might not be good for your site when it grows.

2

I must also chime in here with VistaDB as an alternative to SQL CE.

VistaDB does support encryption (Blowfish), it also supports TEXT as well as NTEXT (including FTS indexes on them).

And yes the post above is correct in that you have to look at the SQL Server types to really match them up, VistaDB also uses the SQL Server types (we actually support more than SQL CE does; only missing XML).

To see other comparisons between VistaDB and SQL CE visit the comparison page. Also see the SO thread on Advantages of VistaDB for more information.

(Full disclosure - I am the owner of VistaDB so I may be biased)

Community
  • 1
  • 1
Jason Short
  • 5,205
  • 1
  • 28
  • 45
  • 2
    Its too bad VistaDB jacked their price to $1295. It was only $299 and I was seriously considering the purchase. No chance at the new price. –  Feb 22 '11 at 23:28
1

There are constraints... Joel seems to have addressed the details. SQL CE is really geared for mobile development. Most of the "embedded" database solutions have similar constraints. Check out

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
  • Those are definitely NOT the real limitations. – Joel Coehoorn Jan 02 '09 at 18:10
  • So where is a good source of info for someone looks to start with SQLite - and use it specifically with MS Visual C# Express?? – adeena Jan 02 '09 at 19:17
  • The SQLite link I posted is a full ADO.NET 2.0 implementation. Short of that, pop over to the original SQLite page for reference and documentation... http://www.sqlite.org/docs.html – Anthony Mastrean Jan 02 '09 at 19:50