2

How can I publish a C# project with a .mdf database? I would like that it can be setup easily and need not install a sqlserver. Do I need to change to .sdf? The Project only uses it in local.

08Dc91wk
  • 4,254
  • 8
  • 34
  • 67
Sevenup
  • 21
  • 2

4 Answers4

3

.MDF files are SqlServer main data files, i doubt you can use them without SqlServer installed, as for SqlServer Compact Databases (.sdf) they can be used like you want but converting from one to another isnt just a matter of changing the extension, they are db with different formats.

You would need to create a new .sdf and replicate the schema you have in your .mdf and then copy your data somehow, also you would need to adapt your project since access to data on an .sdf is different than an .mdf not to mention .sdf doesn't support all the things that .mdf does

JoaoFSA
  • 267
  • 1
  • 7
  • Thanks for your answer but i use vs2013 now and i can't find where i can create a .sdf, [link](http://stackoverflow.com/questions/18598506/is-microsoft-dropping-support-for-sdf-database-files-in-visual-studio) in this link i found that Microsoft drop support for .sdf now ,so may i change to vs2012?i think it's terrible for me,my database it's small so don't worry about converting data&schema,is there a easy way for me to publish my project?:-0~ – Sevenup Sep 05 '15 at 07:38
2

Why don't you simply deploy your application with .mdf file along with a SQL Local DB installation on user machine who doesn't havd Visual Studio installed?

Make sure you install proper LocalDB. i.e. x86 version of installer on 32 bit and x64 installer for 64 bit machine. There is two different installer for both achitechture.

hypheni
  • 756
  • 3
  • 17
  • 37
  • Like he said he don't want to install sql server – Marcin Sep 04 '15 at 13:15
  • 1
    @Marcin: Probably he don't want to install the complete SQL server package, but a LocalDB can be installed without any hassles. – hypheni Sep 04 '15 at 13:21
  • it may be a good way for me , i will use this if i can't find a better way~thanks. – Sevenup Sep 05 '15 at 07:55
  • @hypheni:my bad, you are right. More information about your solution can be found here: http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx – Marcin Sep 07 '15 at 08:28
  • @Marcin: Thanks for sharing the link. – hypheni Sep 07 '15 at 17:22
0

Sql Server is not installed as part of Windows installation, so you cannot use an *.mdf file in your app unless Sql Server has been installed and you have appropriate permissions for it.

It is possible to distribute either Sql Server Express Edition or Sql Server Compact Edition (recommended) with your app.

Hussain Patel
  • 460
  • 3
  • 10
  • 24
  • Why do you say Compact Edition is recommended? Newer Visual Studio version droped support for it some time ago and now LocalDB seems to be the recommended way to go. Also, Compact Edition can't work with an MDF file. – crashmstr Sep 04 '15 at 13:23
  • localDB is this[link](https://msdn.microsoft.com/en-us/library/ms233763.aspx) [link2](https://msdn.microsoft.com/en-us/library/ms171890.aspx)?I had do follow the link and i finish my project and run it successfully,but after i publish it and install in another PC,I found it can't operate the .mdf ?Do you know how to work out it? – Sevenup Sep 05 '15 at 07:51
-1

MDF files are part of SQL server databases. Without SQL Server (or Express), you can't use them.

If you need an embedable database, SQLite is a good option. Firefox also ships with an embedded SQLite instance, so it's a good/proven option. SQLite also integrates well with ADO.NET; I wrote an article on that here.

ashes999
  • 9,925
  • 16
  • 73
  • 124
  • Yeah I know it's a good way to use sqlite, but my Product Manager don't think so and he ask me to use sqlserver because he think it's better=.= – Sevenup Sep 05 '15 at 07:59