SQLite with Entity Framework - c#

Hey folks,
I'm developing a small console app, that should parse text and place data to an SQLite db, app written in C# 3.5 + Entity Framework to persist data to the SQLite. Everything works fine expect that fact that after app did its job I can't find data in the SQLite file. During app running I can persist and read data from db but when it's done I open db in SQLite Administrator (http://sqliteadmin.orbmu2k.de/) and found no data.
Does anybody know what's wrong? Thank you.

Are you sure you're not configuring your SqLiteConnection to use an in-memory database, or a temp file in the user store? SqLite can set up a database almost anywhere, for almost any length of time, and its default behavior may not be what you expect.

So silly from my side, app after deploying to the bin folder copied db file there as well and manipulated with that db file, data is there.

Related

If I create a C# desktop application with SQLite, will the database get bundled with the installer?

I am trying to make an application for managing a small store, which will be offline. I am considering using SQLite for my data handling needs. Once I create the installer for this project, does the database get attached to the installer or will have have to take additional steps to make the application work.
Also is SQLite the best way to approach this or should I consider something else?
Since SQLite needs a file to work with you can include a file which contains empty schema of your SQLite database in your setup project and copy it to working directory. Or add your empty db file as a resource to your application. And in your connection string builder/provider check existence of the file if it doesn't exists read it from resource and copy to the target location. And also SQLite is good option for that kind of usage.

SQLite C# and Firefox Manager

I am writing a small library that all it does is opens a connection with the local SqliteDb present just near the application and reads from the database depending on the search query.
The one using this library does not need the access to Insert or update any record but are updated from lets say me.
SO to create a database i use this:
SqlConnection = new SQLiteConnection("Data Source=Languages.db;Version=3;New=True;Compress=True");
Than to access the database the same but New=False
Now i am using Firefox Sqlite Manager to modify the table such as creating the structure and adding values.
But when i save the file with firefox i get an error on C# stating that it is write/read protected when i try to open the connection!!
Edit: I also tried to use Sqlite Browser: http://sqlitebrowser.org
but then i got that unsupported file format!
Am i missing something?
Regards
The FireFox SQL Lite Manager when open, restricts other applications from making a connection to the SQL Lite database. If you shut down the FireFox Manager, your C# code will execute correctly.
You can refer this answer to understand the nature of the lock applied by Firefox Firefox locks places.sqlite
I have noticed that when creating a table or altering the table somehow from the SQL manager gui, the gui itself creates some headers/meta data that the driver is not able to read and thus it flags it as corrupted.
To solve the issue all i had to do is create the tables and alter as necessary from my application directly,than i can add records using the firefox manager and it seems to be working correctly!
Correct me if im wrong!

Release plan for my application on other machine by using .mdf file

I am using SQL server 2008 R2 and VS2010. I made simple application by using this tools. I attach database as .mdf in my application and deploy that application on other machine its works fine. Now if I plan for new release of my app which some extended features, I can upload Code by DLL, But problem is updating .mdf file, to handle this I am exporting database into .xls sheets (Application have one utility to backup database) and then import into SQL Server to create new .mdf file. Someone have better solution on this? Can I open old version of .mdf file in SQL Server(Third party software) and Execute DML/DDL script on it to make latest code and database compatible ? May I keep .sql file in one of my project code and execute it by some utility..? Any Class in C# which can handle this..?
I did not get your query completely. Do you want to upgrade the DB through the application?
You can of course run .sql files through your application, but I'm not sure it would help you change the Database configuration.
Alternatively, if you already have the updated .mdf file and the database name is same, then you can follow the following steps.
1. Detach the database by SSMS in the third party environment through SSMS.
2. Replace the .mdf, .ldf and .ndf (if any) in the disk.
3. Attach the updated .mdf file.
This will get the new Object definitions as well as data.
As far as I'm aware, there is no process for merging .mdf files, because the SQL Server might not be able to identify the similar objects properly as sys tables may be different, and also would not know which data to keep in the final data base, in case the table structure, constraints or data conflicts occur.
However, looking at your requirement, the best way I can suggest is,
1. Generate the Alter scripts for the tables modified (By right clicking on the object name and using Script Table As.. option). Of course, I assume you have the list of objects modified and the modifications.
2. Connect the two DB servers over network and write an SSIS package or Import data from the old DB to the new one for the tables you want.
Hope this helps.

WPF + SQL Server Compact Debug and Deploy

I have a WPF project set up to use a local SQL Server Compact database through an ADO.NET Entity Data Model in Visual Studio Express 2012 for Desktop. The project works great, on first run I can load all of the data, manipulate it as I please and come back later with the changed data still in place.
I noticed while doing a little restructuring to the schema that the data visible to VS was only the very first bits of data that I entered manually when creating the database and the next time I compiled all of the data I had added since was gone!
After some digging, I came to the conclusion that the compiled version of the app was using the SDF file sent to the bin/Debug folder by the file's Content:Copy If Newer build action. This means that there could be as many as 4 different copies of the database to be worried about: project folder, debug folder, release folder, and the deployed copy on the end user's PC.
I would like to have a single copy of the database on my dev machine that is accessed by both debug and release compiled versions and the database explorer in VS that is installed on the end user's PC by ClickOnce. I suppose I could change the connection string to an absolute path during development and hope I can remember to change it back to relative before I publish for deployment.
Finally, I foresee the need to release updates for this application as well and am worried that such an update would erase the end user's data if improperly done. If possible, I would like to be able to only update the schema of the end user's database without touching the data itself whenever I release an update. If this is not possible that is acceptable and I'll just have to make sure I put every structure I can think of into the database before my first deploy.
In summary my questions are the following:
How to share a single sql compact database between VS, debug, and release?
How to handle local database during application deployment and updates, with the optional ability to update the database schema without erasing the data?
I have a similar application and I keep the database file completely separate. Because you may also need to do updates that you don't want the user database overwritten. I have a process that checks the database schema before the EF connection takes place. So when my users install this application it requires they download the database file from my webserver and puts it in a specific location on their computer.

What database to use if I need to deploy an app with one small table?

I need to create a very simple app that has one table that will need to store records over time. What is the best way to do this with vs 2010 if i do not want to install a database engine on the end users machine.
I would like to just package up the database file with the exe when deploying. There will only be one user accesses the table but i do not want to have to install sql express on the end users computer.
Any suggestions? Thanks!
You might be looking for SQL Server Compact Edition - if it is just one table and not very much data you might consider just using an XML file as well though.
Some suggestions:
(typed) DataSet using Write() and Load() to save the data to an XML
file (very convenient with Visual Studio)
SQLite
Object serialization
Try either SQL Server Compact or in another scenario which I dont like MS Access.
http://en.wikipedia.org/wiki/SQL_Server_Compact
http://en.wikipedia.org/wiki/Microsoft_Access
Some options for embedded relational database systems:
SQL Server Compact Edition
SQLite
Firebird
For a more complete overview see http://en.wikipedia.org/wiki/Embedded_database
if you want to save data very simple,you may Serialize data to XML file, or if you want to save as smaller.
Add Dataset, when you start program load it to memory, when you close program you may save it as xml file.

Categories