Switching from using SQL Server Express to SQL Server Compact - c#

So far I have been using SQL Server Express on my desktop application even though usually the server is only used by that single application, by the single user, on the same single machine. This always seemed a bit silly to me since the full-on server is rather heavy.
Then I found out that there is something called SQL Server Compact. Thing is, my application is already rather large. So my question is that if I wanted to change to SQL Server Compact, what kind of changes to my code are we talking about (using C#)?
Mainly I'm wondering if I can access the Compact -version in the same manner as I can access the Express one, which is using ADO.NET and pointing it towards localhost\sqlexpress. So would it be possible to create another instance with the Compact and just point my application to that, or is it used in a completely different manner?

For a standalone desktop product it is certainly a lightweight option to consider over SQL Express.
However there are differences between the two to be aware of other than just connection strings. For example SQL CE does not support stored procedures, user-defined functions, or triggers. Additionally it does not support the full range of datatypes that Express supports. On a technical level it also runs in process with your application.
Another consideration is that while SSMS will work with SQL CE databases, it's not as fully featured as it is with SQL Express. There are however a whole raft of good tools out there for filling these gaps. Take a look at Erik Jensen's blog for a good overview.
Everything SQL Server Compact
Also check out his tool for migrating SQL Express databases to SQL Compact:
How to Migrate/Downsize a SQL Server database to SQL Server Compact 4.0 (and 3.5)
Finally take a look at this SO question for more background between the two products:
What are the limitations to SQL Server Compact? (Or - how does one choose a database to use on MS platforms?)

I worked recently with it, by the way the things I know about using them is that SQL Express has a server to connect to, and, Compact is a sdf file, so the first thing you will have to change is the connection string to it.
After this change, there are no more heavy changes to be done, I remember, compact has almost all the instructions of the express server available, so, it could not be much problem.
Take a look at Microsoft documentation for more information, or at Wikipedia.
See you.

I would vote against SQL CE:
It has no views, which might be an issue when migrating.
We recently did something similar which you described and had tremendous performance impacts when switching from SQL Server Express to SQL Server Compact Edition.
My recommendations would be:
Use SQLite (which we did for the project I mentioned - it was much more performant than SQL CE in our case) -or-
Use VistaDB (which I did in other projects; not as performant as SQL Server Express, but still sufficient)
Both databases can be XCOPY deployed, just like SQL Server Compact Edition.

SQL CE has the same size limitation as Express, so you should be good.
As far as moving between the two, I found this for moving between express databases and compact 3.5 databases. Then I think you'll only have to change your connection strings (instead of pointing at a host/instance, you point at the converted file). There are different features between the two, though, so you might have to change your schema in the original database for the conversion to go smoothly.

Related

Migrate project from .MDF database to .SDF

I ran into a stupid problem.
I started developing a Windows Forms application in C# that must be stand-alone (work with absolutely no installation) and needs a database. Being genius that I am I didn't read too much into it and used SQL Server Express .MDF database.
Now it works perfectly, with Linq and all it's perks (data context, designer and so on) but what I didn't know is that client machine will need SQL Server installed to work with database. My program will be potentially deployed to 200-250 PCs and installing SQL Server on all of those PCs is not an option.
Is there any way to use a SQL Server CE database instead of .MDF? Or will I have to rewrite half the program?
First, read about SQL LocalDB.
It still requires installation and requires administrator rights for installation. However it supports silent installs, installer size is only 33MB, and it supports the majority of the features of the full-blown SQL.
If you cannot afford any installs at all, then yes, SQL CE might be an option for you. Whether you’ll need to rewrite half the program depends on how exactly you use your database. If you rely on stored procedures, views, raw SQL, other advanced features then yes, you might need to rewrite half of your program. If you only use linq2sql with simple queries, then you might be fine and only need to rewrite the DB initialization code.
Remember the last visual studio that supports SQL CE tools is 2012.
If you can’t install anything at all, and you will be rewriting half of your app — remember there’re many embedded databases now days.
You could instead prefer SQLite: it’s cross platform, extremely popular, SQL language.
Or ESENT: there’s no SQL but it has tables/schema/indices/transactions, part of Windows wince win2k, the performance is really good, 10-100k requests/seconds is normal.

Concurrent access to lightweight/(embedded?) SQL database by several applications on the same local machine?

I am looking for a solution in which several applications on the same machine access one and the same database. Generally the operations are just reads thus I am not interested in having to provide concurrent write access as well.
I checked into SQL Server Express, SQL Server LocalDb, SQL CE, SQLite, MySQL and am not convinced which one is the best solution. I read that SQL CE allows concurrent read access but SQL Server LocalDb does not, which I find very odd given LocalDb is hyped by MS as a version that is very similar in functionality to the SQL Server family and which is supposed to make it easy to later on scale out.
I like to manage 5-10 tables each of which holds less than 5000 rows, so really lightweight content.
I am looking for a solution that meets the following requirements:
Concurrent read access by several applications on the same machine
Should be somewhat lightweight. I intend to move all applications within a solution to a different machine later and do not want to have to install a 200mb full blown SQL Server Ex#ress version if possible.
Should play well with VS2012 express (sqlite and mysql are highly unsupported in that regards, either not supporting EF5 or they do not show up in the server explorer.
Should be an SQL solution in order to manually update database tables within a management console such as Workbench or Management Studio or other third party app.
Should work somewhat with EF or other ORM solution. I want to be able to create an entity class and create a database from that or update tables using class objects. Also I want to populate class object collections from table rows without having to go through SQL code.
I target C# in .Net 4.5 and I guess it boils down to the question whether SQL CE is up to the task to allow concurrent reads and how I can load CE data tables and edit and visualize the content in some sort of management console. Also does SQL CE play well with EF5? Any better suggestions?
Since you're asking for an opinion, SQLite is my answer.
We are aware of no other embedded SQL database engine that supports as
much concurrency as SQLite. SQLite allows multiple processes to have
the database file open at once, and for multiple processes to read the
database at once. When any process wants to write, it must lock the
entire database file for the duration of its update. But that normally
only takes a few milliseconds. Other processes just wait on the writer
to finish then continue about their business. Other embedded SQL
database engines typically only allow a single process to connect to
the database at once.
Entity Framework on SQLite
System.Data.SQLite
Setups for 32-bit Windows (.NET Framework 4.5)
This setup package is capable of installing the design-time components for Visual Studio 2012.
SQL CE Works with EF5 and VS 2012 Express, is very lightweight, supports multiple readers on the same machine, and can be managed in VS Pro+ combined with the SQL Server Compact Toolbox add-in (or standalone) (I am the author)

Free database for Entity Framework in WPF MVVM

I want to use a free database to do some databinding (storage) in my WPF Application (PixelSense).
I have already used SQL Server 2010 with Visual Studio 2010 and it works very fine.
I've heard also that Entity Framework does not work great with MySQL due to some incompatibility issues, and SQLite doesn't support Booleans.
What do you suggest for me in this case ?
Edit
Thank you, I've choosed Microsoft SQL Server 2008 R2 Express
Why : Free, by Microsoft, almost the same as SQL Server
In microsoft world, you can use :
Sql Server Express
10Gb per DB size limitation
Sql Local DB, which is the replacement for Sql Server User Instance. It's part of Sql Server Express.
10Gb per DB size limitation
Sql Compact
4Gb per DB size limitation
As it's Microsoft products, you will have less probability of issues.
My preference goes to Sql Compact because of its low binaries footprint. There are however some limitation (ntext not supported very well), at least in the version I used some years ago.
Good to know, Access database are not supported. While Access has not a good reputation, for local app it make senses.
Outside Microsoft World, SqlLite has a good reputation.

Package tsql with application

How can I release a winform application to a user that takes advantage of a local sql database. I would assume that I need to install the database during some kind of setup phase, but is this kind of thing possible? Is there a free version of tsql that can be used in this way? Mysql?
TSQL is a language specification, not an actual database.
If you're talking about MS SQL Server, it is possible to bundle and install an instance of SQL Server Express, if you want to distribute a database with your app. There's some documentation on it over on MSDN, specifically, Embedding SQL Server Express into Custom Applications.
SQL Server Compact Edition is suitable for this. It has some limitations in that it does not support the full set of functionality that SQL Server supports (ie. stored procedures is one example), but it does mean that you don't need an installation of SQL Server to use it. If you are only using the database as a "bit bucket" to store and retrieve data, then it should suffice.
Another alternative is to use SQL Server Express Edition. This does require installing a proper SQL Server instance, but basically gives you a cut down version of the full SQL Server, enabling you to use more of its features.
Both of these are free.
You might also want to check out VistaDB. It is syntactically compatible (although not perfectly) with sql server. All managed code. But it is not free.
SQL Server Compact Edition does not support stored procs, fyi. But is a single file deployment plus your data file.
SQLite is extremely fast and lightweight. Deployment is single file plus data file. But it has some syntactic limitations and has limitations to its dotnet integration (although I am pretty sure there IS a ado.net provider for it.)
I support an application built on sql express edition and it is a PAIN. It has a lot of install failures. (Probably about 10k installs over the last 3 years.) But if you need to power, hot backup, full sp and function support, connection pooling, etc it will work for you.
Never used mysql so I can't comment.
Seth

Alternative to SQL Server for a simple web app

I have a simple app written using SQL Server, Entity Framework, C# and WCF. When I wanted to share this app with my friends, I realised they didn't use SQL Server on their machine. I could go for SQL Server Express edition, as the usage of my app is personal and non-commercial.
I found MySQL as a popular alternative to SQL Server.
1) Would I be required to update my entities when moving to MySQL?
2) Should I anticipate code changes in my BL layer due to change in entities layer? (I am wondering whether entities was built for SQL Server)
Are there any databases similar to MS Access that is lightweight compared to MySQL?
Are there any databases that need not be installed but can be copied around like MS Access?
Appreciate your response!
Sounds like you want SQLite.
SQLite is a software library that
implements a self-contained,
serverless, zero-configuration,
transactional SQL database engine.
Very easy to deploy. Also, check out System.Data.SQLite.
According to the System.Data.SQLite page ...
Supports nearly all the entity
framework functionality that Sql
Server supports, and passes 99% of the
tests in MS's EFQuerySamples demo
application.
You should be good. :)
Im not sure how your BLL looks like and i have no experience with entity framework, but ive experienced multiple times that linq-to-sql works much better with sql-server as with any other database.
So unless you have a good reason not to use sql express, i'd advice to stick to sql express.
After all, you should always install something when deploying (unless you use xml as storage, which is quite well possible with linq-to-xml).
VistaDB Express Edition is also free for non-commercial usage and integrates good into .NET and VS. afaik it also works on a single local data file thus requires no specific installation on your friends' computers.
Otherwise I recommend using PostgreSQL over MySql since it is more standards compliant and has a nicer license.
I think what you're after is just a change in providers. What you need to use MySQL is the .Net Connector which supports most everything simple. It's not very mature yet so something very complex you may have issues on, but it should do most of what you want through Entity Framework.
With Entity Framework yes you can do updates, it's LINQ-to-SQL that doesn't update against any other databases (unless you use a third party provider like DotConnect)
SQLite is one alternative, but since multiple threads against it can cause major issues with it's operation, so if you need a major data store I'd go SQLExpress or MySQL.
Yes, you could use MySql with EF but I don't know if it would require changes.... I wouldn't be surprised if it does though. At the very least your physical DB would have to be ported / converted to MySql and that will take time.
I would assume that if you need to install a DB on your friends Pc's why not stick with SQL Express since you already developed in SQL Server on your box. Should be less issues with this than migrating to MySql.
I'd also vote for VistaDB 3 as it's so easy to deploy.

Categories

Resources