I have a need to try and repair a SQLite database from a .NET program if the database file gets corrupted. I have found several sites such as Fix SQLite and in the FAQ it describes that you can:
Depending how badly your database is corrupted, you may be able to recover some of the data by using the CLI to dump the schema and contents to a file and then recreate.
Does anyone know of a way to repair a SQLite database programmatically in .NET?
You might consider implementing your own strategy for database recovery. You could store backups of the SQLite file and then check that it is OK using:
PRAGMA integrity_check;
If errors are found then you can revert to a backup.
You are overlooking one important word: you can 'recover some data', this is not a repair!
If there is a sitatuation where a corrupted database could be repaired perfectly without user-interaction than it would not be corrupted in the first place and such an repair would have been a standard function of SQLite
Related
What is the possible solution for this? I force execute the SSIS Job
but the error encountered is
Microsoft jet database engine cannot open the file.''. It is already opened exclusively by another user, or you need permission
What is solution for this I already change the security
This is the flow of the SSIS. The process of this is to update the data of the SQL Server coming from the MDB.
If I'm ever required to use a communal data source like this, especially if the tooling (Excel/Access) takes an lock when someone is just looking at the file, I find it beneficial to copy the file elsewhere for processing.
Before your Update Control Rate data flow, have a File System Task. Define it as a copy with overwrite/clobber/replace from \\server\share\TDMAT TEST\TDMAT.mdb (or whatever the obscured path is) to a local folder that SQL Server Agent/Service Account/SSIS credentialed account has read/write access to. I usually have a folder defined like C:\ssisdata\data_domain\input. So, copy TDMAT.mdb to C:\ssisdata\tdmat\tdmat.mdb.
Then, you have your JET connection managers reference the local file. Away goes your concurrent usage issues. The clever among you might question why we can copy a file that is "locked" but not read it and I can't tell you the why, just that this approach works.
I have a C# .NET Framework 4.0 desktop application with Entity Framework as DAL.
When a try to save a data into DBContext on anybodies machine but mine, I recieved an exception
Failed to update database "*.mdf" read only
I keep my DB near .exe file, in folder "DAL/AppData".
How can I allow write access on other machines?
Can I do it programmatically?
I've read that I can place DB into AppRoaming Folder, but this is not my variant.
Thanks in advance.
I keep my DB near .exe file, in folder "DAL/AppData".
Yes. Can it be you mean that this is in the programs file folder, you know.
THe one that windows specs of the last 10 years say is "read only" for normal users?
OUCH.
THer are folders for storing data. There is a SpecialFolders enumeration to get the valid path of every such folder.
How can I allow write access on other machines? Can I do it programmatically?
On a SQL Server, this is done by allowing the other computer to access the server, not the data files. I.e. you connect to the SQL Server on the other machine, which is having the database loaded.
I've read that I can place DB into AppRoaming Folder, but this is not my variant.
First, that would be stupid unless you do actually plan for roaming - SQL shold go into a local folder, never roaming.
Second, "not my variant" is like "Hey, I drive the car against the rules, what can I do not to get speeding tickets". And "following the law is not my variant". Your variant is something WIndows does not care for. Learn how to install your software according to the windows guideline which is VERY clear where changing data should NOT be.
In Microsoft Visual Express is there a way to export the SQLite database I've created through the Express interface into a code format so I can have it generated on first install by my customers?
I'd like to take the easiest way to do this without having to manually prepare all the code structure.
I was unable to find any sort of export feature. Any advice?
This resource will help me execute the code once I have it prepared, but I've 12 tables and some of them should come pre-populated, so being able to have the batch code will help.
If it's just an SQLite database you could just publish the file with the rest of your program since it's a normal file without any dependencies.
I am writing a plugin for a C# application which uses SQLite database. The initial database is stored in database.db.default. At any point during runtime the user should be able to reset the database to the default content.
Since the application has always an open connection to the database I can not just copy database.db.default to database.db.
Whether or not it is a good idea to always hold an open connection is a total different question. But that is just how it is since it is not my call to change that part of the application.
Is there any way I am able to restore database.db.default into database.db using C# and .NET 3.0?
I appreciate any kind of help ...
If you can't do a file copy to restore the database then do the restore the hard way. Attach the backup database, delete all the data in the main database, then insert the data from the backup database.
I'm probably missing something here, but can't you just close your connection and reopen it after the copy?
I have a program in C# that uses an MS Access database and I'm using OleDb to connect and do queries on that database. My issue is that I have some sensitive info in the database and I don't want it to appear as an Access DB. I changed the extension, but when I open it, it still creates the .ldb lock file used by Access. I want to have the DB not create that lock file.
I have read many posts on the issue and it sounds like if I open the DB in Exclusive mode, it will not create that .ldb file. However, so far, I have not found any connection string for OleDb that lets me specify Exclusive access to the DB. The OleDbConnection object in C# has no "Mode" member either, so setting exclusive access that way is out of the question.
If anyone has any connection strings that can open the DB in Exclusive mode, or if anyone knows another way to avoid creating the .ldb lock file in Access, the help would be much appreciated.
http://www.connectionstrings.com/access has an entry for Ecxlusive mode.
I would recommend using SQLite or another non-access option if you want to avoid lock files.
Trying to avoid the lock files is difficult at best. Even if you open the file in exclusive mode, JET creates these files at times.
If you're trying to store sensitive data, and you want to "hide" the type of file, another good option is VistaDB. It's a single file database, but allows full DB encryption. This would probably be a better approach than just trying to mask the fact you're using JET.
You can't really hide that it's an Access database. Anyone can open the file in a hex editor (or even just notepad) and see a string like "Standard Jet DB" (Office 2000/XP/2003) or "Standard ACE DB" (Office 2007) staring right at them. Even if they don't know what that means Google will tell them soon enough. You use could a less-common database, but they will have similar weaknesses.
If you really want security, you're going to have to encrypt the database file and use an engine that will let you keep a decrypted version in memory (IIRC sqlite supports this, or will soon) or use an engine that supports encryption natively. Even then, you can have problems if the ram is paged to disc or if another process "sniffs" your app's ram.
A late update, but my attention was drawn back here today and I wanted to add that just about anything but Access will require you to distribute the engine with the application. You need to also take care that the files for the engine don't give it away as well. Access gets a pass because the engine is already part of windows. You might also try something that's open source, so you can re-compile it into your main application file.
I have several databases with the Exclusive flag set, and I still get .ldb files created each time I open one. If you are really worried about security it's time to move to a 'grown-up' database.
Install SQL Server 2008 Express, use upsize wizard in Access, point to your Express instance.
You could also potentially use Sql Server Compact to do this. It is free and part of Visual Studio. It is actively used by Microsoft in quite a few products, including Windows Live.