0

I am new to C# and SQL Server databases, so this may be a stupid question but I am confused.

I want to setup an embedded database on a client machine automatically when he installs my application. I know SQL Server Compact Edition is there but there are so many restrictions in SQL Server CE.

Can I use .mdf files as an embedded database? If yes then how can I setup it on client machine automatically? or is there any other option to solve my problem?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Yes, this could be done. If you don't need more than a single database you might also consider looking into SQLLite – drew_w Feb 10 '14 at 19:20
  • Contradicting @drew_w here: but **NO** this cannot be done - in order to use an `.mdf`, you always **must install** some form of a SQL Server **server-side** component. An `.mdf` file cannot be used by any "embedded" database that you can ship as a set of DLL's with your application - `.mdf` need a SQL **Server** to run – marc_s Feb 10 '14 at 19:42
  • There is apparently a way, but it's not simple: http://stackoverflow.com/a/10800781/542417 – bouvierr Feb 10 '14 at 19:48
  • @marc_s Technically true, but I think there's a fair chance that SQL Server LocalDB is sufficient for the purposes of the OP, even though there are good reasons for not actually calling it "embedded". –  Feb 10 '14 at 20:15
  • @hvd: okay - but even "LocalDB" **requires** an installation! You cannot just ship a few DLLs with your app (which is what I'd consider an "embedded" database) - it's really still a **server** running on that PC where the app runs – marc_s Feb 10 '14 at 21:28
  • @marc_s Fully agreed, I just think the OP may not be aware of such an option, so the word "embedded" in the question may not be intended to exclude such an answer. –  Feb 10 '14 at 21:37
  • @marc_s The point of the question is to ask if there is an easy way to deploy an MDB to a client as part of an application. I don't think the OP cares about the semantics of the word "embedded". To that end, what they are asking for is possible. SQLLite is a much better solution. – drew_w Feb 10 '14 at 21:51

1 Answers1

0

I would recommended to use SQLite. It is simpler to deploy. Also, SQL Server Compact appears to be discontinued.

Is SQL Server Compact discontinued from Visual Studio 2013?

You can use SQLite which doesn't require any installation on the client machine.

SQLite depends on the Visual C++ runtime, but you don't need to install it on the client machine. The system.data.sqlite download page contains several "static" packages that already contain the runtime.

All the "static" packages contain either native or mixed-mode assembly binaries linked statically to the appropriate version of the Visual C++ runtime. Typically, these packages are used in cases where customer machines may not have the necessary version of the Visual C++ runtime installed and it cannot be installed due to limited privileges.

For example, on my machine I am running Windows 8.1 x64 so I went under Precompiled Statically-Linked Binaries for 64-bit Windows (.NET Framework 4.0) and downloaded sqlite-netFx40-static-binary-x64-2010-1.0.90.0.zip.

This binary package contains all the binaries for the x64 version of the System.Data.SQLite 1.0.90.0 (3.8.2) package. The Visual C++ 2010 SP1 runtime for x64 is statically linked. The .NET Framework 4.0 is required.

I then unzipped the package and ran test.exe to make sure everything works. Zero installation required.

Community
  • 1
  • 1
bouvierr
  • 3,563
  • 3
  • 27
  • 32
  • thanks dude. it's really helpful. but my client keep preferring sql-server database. :( is there any way to use .mdf or sql-server express as embedded database? if not then last option is SQLite for me. – user3149221 Feb 10 '14 at 19:36