Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to access a .mdf database without SQL Server?

Tags:

c#

sql-server

mdf

I created a .mdf file by SQL Server and put it to a local file. I run my program in a computer which has no SQL Server installed. And also I used classes from the System.Data.SqlClient namespace (i.e. SqlConnection..)

I want to make some kind access connection with .mdf file which was created by SQL Server? Is it possible ?

like image 435
unbalanced Avatar asked Apr 28 '12 18:04

unbalanced


People also ask

Can I use database without server?

SQLite is an example of a classic serverless database engine. With SQLite, there are no other processes, threads, machines, or other mechanisms (apart from host computer OS and filesystem) to help provide database services or implementation. There really is no server.

Can I use SQL without SQL Server?

Your best option is to use an access database. You won't need to install anything on the machine it is virtually like using a flat file that can be queried like a database :) I think I would go with your solution for the time being.

How do I view an MDF file?

Step 1: Run MDF Viewer and Click on Add file Button. Step 2: Browse the MDF File the system and select the Scan Mode. Step 3: Software Starts the Scanning Process. Step 4: Preview the SQL database objects such as Table, stored procedure, triggers, functions.

Can access open MDF files?

Microsoft Access can't process an MDF file. That requires SQL Server. If you want to use Microsoft Access, you must have a copy of SQL Server running, with the MDF file attached. You can then create Linked Tables that enable Access to treat tables in the SQL Server database as if they are local tables.


3 Answers

I don't think it is possible to interact with an MDF file without going through a SQL Server engine. You would most likely install SQL Server Express (which should be an option if you choose to go through add/remove programs for Visual Studio, or you can download it separately from here - this is the 2008 R2 With Tools option), attach your database, and then connect to that engine from your program.

Many tutorials online will suggest you use the User Instances feature and AttachDbFileName. I suggest you don't go that route as it often leads to confusion - many, many users connect to one instance of the database through Management Studio, a different instance from their program, and then don't understand why one doesn't see the updates made by the other. The User Instances features is deprecated and I highly prefer attaching a database to the instance properly.

In SQL Server 2012 you can download the new SqlLocalDb runtime (you want either the x86 or x64 SqlLocalDB.MSI file from here), which makes this process much easier, as it is a no-maintenance on-demand SQL Server engine. However note that your database will be upgraded to the new 11.0 file format, which means you won't be able to detach/attach or backup/restore to an older version (2008, 2008 R2, etc). I added many troubleshooting techniques for new users starting with SqlLocalDb here.

like image 123
Aaron Bertrand Avatar answered Sep 28 '22 17:09

Aaron Bertrand


You may try using OrcaMDF which is an open-source project.

What is OrcaMDF?

A C# parser for MDF files. Allows you to read tables, metadata and indexes from MDF files without it being attached to a running SQL Server instance.

(this description is taken from project's page).

Author's blog

like image 41
Bogdan Sahlean Avatar answered Sep 28 '22 18:09

Bogdan Sahlean


You need SQL to connect to the MDF. You can convert it to an SDF and load the compact edition (free). http://msdn.microsoft.com/en-us/data/ff687142

like image 25
tzerb Avatar answered Sep 28 '22 16:09

tzerb