Dumping an SQLite database stored as dll file? - c#

A little background first: I need to extract a database from an SQLite dll file for my client who has burned bridges with the previous dev.
I have these 4 files sitting on my desktop:
System.data.SQLite.Linq.dll
System.data.SQLite.dll
SQLite.Interop.dll
Payroll.exe
I am also given the password for the SQLite DB which Payroll.exe uses to interact with the database. With this is it possible for me to dump an SQL file (so I can work with something familiar)?
Major problem is that I have no experience with C#, .NET stuff and DLL files (I know it stands for Dynamic Link Library!)
I'm willing to dabble and learn some C# to do this.
As suggested, I decompiled the source and found some interesting code:
namespace Payroll
{
internal class Payroll_Database
{
private static string ConnectionStr = "Data Source=.\\System.Data.SQLite.Linq.dll; Password=******!";
private static SQLiteConnection Connection = new SQLiteConnection();
It seems certain that System.Data.SQLite.Linq.dll is the database file. I have trouble opening it with tools such as SQLite Browser. I have tried renaming it to a .db, but again no dice.

Your database won't be in the dll and exe files you list.
It should be in a separate file, possibly with an extension like .sqlite, .sqlite3, .sdb3 .db or .db3 (but this is not mandated).
If you can locate the db file, you can open it with any sqlite client (e.g. you can use the firefox sqlite-manager plugin), and extract the data as required.
You could probably find the database filename from the Payroll.exe source code, which you can read by opening Payroll.exe in ILSpy.
If you cannot locate the db file, you will be unable to retrieve the data. In which case, the best you can achieve with the files you list would be to determine the database schema by reading the payroll application's source code.
Update:
Now you've found the connection string, it looks possible that the database could indeed be the System.Data.SQLite.Linq.dll file, and the developer has given it a name to match a known .NET assembly as some kind of security through obscurity.
If that is indeed the db file you should be able to open it directly in a SQLite client application like the firefox sqlite-manager plugin I mentioned above. If you can't open it in a SQLite client application, then you can to check to see if it is a .NET assembly after all by opening it with ILSpy or Microsoft's MSIL disassmebler.
Update 2:
According to this SO question, you should be able to open your encrypted db file with the free SQLite2009 Pro Enterprise Manager.

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.

How to read data from embedded database?

I wanna improve one application which database is unknown for me. So i have interface to work with but no data to fill forms/documents etc in a new application... Installation folder only containts .dll files without any clue of database. For now i have tried to inspect .dll files with JetBrains and found only source code of those dll's without any "physical" location of database on my hard drive so i started to think it's embedded in application. I also inspected all my hard drive to try find it in some hidden folder without success. After further investigation i figured out that i have to get Microsoft Access database who works with Jet Oledb 4.0.. I found this line of code where it says :
this._connectionString = "PROVIDER=microsoft.jet.oledb.4.0; Data Source=" + this.DataBasePath + "; Jet OLEDB:Database Password = 12345678";
So basically i know the password of that database but i don't know where is that database. And now i am stuck because i have never worked with embedded database. I only got installed application and installation file (which was generated thru visual studio).
Is it possible to get tables/data from embedded database and if so how to do it? Is it maybe possible to get database from installation file and if so how to do it?
Any help would be nice.
Thanks KuKeC
Unless I'm wrong there has to be an actual file to store the database so why dont you just look for a *.db file in your system and open it with a db tool to check the content

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.

How to browse or extract an old (.db) file

i have an old (.db) database file and i need to extract the contents of it or to use it with a c# application but i dont know which software to use please help me
check this link that lists the db file types.
http://www.file-extensions.org/search/?searchstring=db&searchtype=2
thank you
Well, checking the link in your question, I could browse through the apps that were related to DB extension. And after a quick analysis, I think dBASE will to what you need.
http://www.file-extensions.org/dbase-file-extensions
It allows you to open, edit, save and convert to another extension that might suits you better.
I guess that MS Access and SQLite can do the same thing dBASE will do for you.
The problem is, that *.db has been used by many programs.
Using any Unixoid system (Linux, BSD, MacOS) you can use the file(1) utility to get the program which probably created that file. Using this information you can then ask for more specific help here.
As an example for my *.db files and the output of file:
/etc/libgda-4.0/sales_test.db: SQLite 3.x database
/home/XXX/.mozilla/firefox/cert8.db: Berkeley DB 1.85 (Hash, version 2, native
/var/cache/man/cs/index.db: GNU dbm 1.x or ndbm database,

How to backup SQL Server database (mdf) programmatically to later import it rowwise?

My aim is to backup a database (.mdf) as one file with my web application project written in C#.
The backup should later on be loaded on a "restore"-page, where the data in the backed-up tables could be appended to the original database row by row.
What would be a good practice to implement this?
I thought of just copying the mdf file, but then I read about attaching and detaching of the database. Furthermore I don't know what to do with the _log.ldf file.
I'm looking forward to your hints. Thank you in advance for your help!
EDIT: I can only use the free SQL Server Express for this, because I want to distribute my program to other people.
Probably, you refer to the Backup and Restore using C# for Sql Server to get a complete idea about writting a code in C#, which has helped me a lot when I was using it.
By the use of Backup class in C#, you can get all the facilities to backup as well as restore.
If you are only interested in appending the data rowwise afterwards, perhaps it is easier to export each table to CSV and import it afterwards (so you have rowwwise control in C#).
If you insist ine one file, just add all the CSV's to a zip.
You can use the FileHelpers library for this (http://www.filehelpers.com/) and you will have it up&running in no time.
Apparently there is a Backup class in the SQL Server Management Objects library.
You might want to check that out first, as it doesn't look overly complicated:
http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.aspx
It would require you to have two or three libraries installed on the server you run it on, though they are fairly small - not Windows SDK sized...
pls go through this link on how to backup data and restore using c# and sql server .In addition to you have to add these names spaces
Microsoft.SqlServer.Management.Smo;
Microsoft.SqlServer.Management.Common;

Categories