0

I am in highschool and I'm going to this contest with all my region. So I have to be the best.The problem is that I am not allowed to go with my laptop there and I have to work, offline (only the MSDN Offline Help), on their computers. And the version of C# there is 2008 or 2010 (depends on the PC).

My question is: How can I solve the next problem Without installing anything on the computer:

I have a database .Mdf file.And my program needs to be portable so I have to use in connectionsting |DataDirectory|,but the problem is when I'm inserting data etc. The data doesn't save if I close and open again the program.

Some guy answerd me and telled me that it's beacuse of the connection string. And because I have to install "SQL Server Management Studio Express", but obviously I can't do that on their PCs.

So do you guys have any idea how can use a database with |DataDirectory| without having any problems with saving data after closing the program?

rene
  • 41,474
  • 78
  • 114
  • 152
Dabuleanu Catalin
  • 59
  • 1
  • 1
  • 15
  • Create a DataTable and use the DataTable as your database. You can read/write the DataTable as an XML file so you can read it on another computer. You can use XML instead of Mdf. – jdweng Mar 27 '16 at 20:16
  • If you're using a `.mdf` file, you're using **SQL Server** and you **must** install a SQL Server instance - Express edition or otherwise. You cannot do without installing a SQL Server instance – marc_s Mar 27 '16 at 21:01

1 Answers1

0

First you want to have have portable application, I recommend you to keep a simple solution and to use a Microsoft Access file as database. The Microsoft Access database is not good solution for medium/large databases, however if you don't have more than 5000 or 10000 records it should be more than enough.

The good part of use a Microsoft Access is that you don't need to deploy MSQL and dump all the Tables (Or copy the mdf file). You just need include the accdb/mdb file with your application or copy it into a writable location (Like My Documents)

You can open the .accdb or .mdb file using OLEDB with a connection string like this:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;

Persist Security Info=False;

Check http://www.connectionstrings.com/access/ for different connection string examples.

Check this example that includes SQL: SQL connection string for microsoft access 2010 .accdb

Good luck with your project!

Community
  • 1
  • 1
Juan Lago
  • 960
  • 1
  • 10
  • 20