3

i am making a WPF program. This program has a database and dataset. The software is working great on the computer i made the program on. Today I tested the software on another PC. But it was not working because it couldn't find the SQL server.

So that is a problem. I thought it was local so I can use it everywhere but that is not the case.

What i want is a database that is portable, so can be used on every computer and it works offline. I don't know where to start and hope someone can give me some tips

6
  • You can use sql server compact edition. Commented Apr 3, 2018 at 22:02
  • @LowFlyingPelican You mean SQL Server LocalDB? CE is dead Commented Apr 3, 2018 at 22:03
  • sqlite may be option. Commented Apr 3, 2018 at 22:04
  • 1
    @Camilo Terevinto correct me if I'm wrong but localdb won't work based on requirements, since it needs a separate install. CE is supported through 2021. Other option is to use sqlite as RajN suggested. Commented Apr 3, 2018 at 22:10
  • LocalDB will work Commented Apr 3, 2018 at 22:13

2 Answers 2

1

You can copy an MDF file around using SQL Server LocalDB (formerly known as CE - Compact Edition).

SQLite is a good option, too. That's what it was made for. Libraries can be found on their homepage here or on Nuget here.

A connection string for the MDF option would look like this:

Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;

More connection strings can be found here:

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reaction. I am integrating SQLite at the moment but i have a problem. when i am trying to add ADO.Net entity Data Model. The SQLite database is not in the connection list? How can i fix this?
LocalDB is not sql CE and never was. A sql ce database is .sdf. LocalDB are mdf.
1

Another option to consider is not to use a database at all. Serialisation and deserialization objects to files is often way faster than any of the database options.

Serialisation is best suited when your data is not hugely dynamic or you're saving multiple relatively discrete chunks. I coverted an app from win ce to serialisation a while ago. It significantly speeded up as a result. Made much more of a difference than I expected.

And of course you can use linq to xml to query filter sort etc.

You can mix this with a message queue such as ms mq and persist the dynamic part of your data you're capturing to disk in a queue. Consider a salesman with an occasionally connected app on a laptop. They could load fairly static data such as product options and costs as xml. Deserialise that in the app so they can put a quote together. They then need to persist the quotes. You could just serialise each quote as a separate file and it'd fly. Or you could persist them using message queue. Have a windows service which looks for when the laptop connects to wi fi. When connected it gets each of the quotes off the queue and sends them to head office by calling a web service.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.