how to read places.sqlite of firefox using c# application - c#

Hi I am trying to get all history url of mozilla firefox. To do that I am accessing places.sqlite file inside %appdata%mozilla/firefox/profile/*.default folder. I am using system.data.sqlite dll in my code and tried x64 and x86 both of the solution. As I am trying to connect the database it is showing me an exception that the file is encrypted or not a database file.
To cross check this exception I've installed a dbmanager for sqlite and opened it. This is showing me all the data that I want to show. But I am not able to get the same data using c# application. Please Help me to get this thing resolved.
SQLiteConnection sqlite_connection = new SQLiteConnection("Data Source=" + dbPath + ";Version=3;New=True;Compress=True;Integrated Security=SSPI;");
SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();
sqlite_connection.Open();// exception occurs here

Related

C# application deployment issue with .mdf database

I am working on a C# database application for learning and I'm trying to deploy it on client machine and getting connection problem.
//NOTE: path and database variables have correct info because it works on my dev machine
"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=" + path + "\\" + databaseName + ";Integrated Security=True"
I am using Install Shield for creating setup and tried Advance Installer also.
On the other test machine I have installed:
.Net Framework 4.5.2
SQLLocalDB.msi (x64 bit)
Lastly, I installed my deployed setup file and I was getting an Exception:
System.Data.SqlClient.SqlException (0x80131904). A network related or instance-specific error occured while establishing a connection to SQL server.
The server was not found or not accessible.
Localdatabase Runtime error occured.
I also tried these in Connection String: (found in similar question on stackoverflow)
localhost
localhost\\SQLExpress
.\\SQLExpress
But none of this work for me.
NOTE:
My LocalDB connection string is working on dev machine.
Using Visual Studio 2015 Enterprise
PS: What I am trying to learn is a way to create an installer which installs some per-requeisites like .Net Framework, LocalDB etc and can run database based application on client machines without installing SQL Server separately. I am not sure if the .mdf way is the good fit for this or not.
I would suggest you to use SQLite Database because the process and function are almost similar. And the deployment is super easy; it just requires few DLLs to make it work.
Guideline:
First you will need System.Data.SQLite library and then needs to add System.Data.SQLite.dll as a reference in your project. Keep in mind that SQLite.Interop.dll also needs to be in your executables directory but doesn’t need to be added as a reference in your project.
Moreover, if your application is targeting Any CPU it is likely that you will get an exception. So make sure to navigate to Project properties -> Build and set the Platform target to the bit version of the System.Data.SQLite.dll binary you have downloaded.
As you are beginner so here is the step by step guideline along with sample code.
Steps:
Navigate to: Tools > NuGet Package Manager > Manage NuGet Packages for Solution
Search For: SQLite
Select System.Data.SQLite (would be first result)
Click on Install
Import library
using System.Data.SQLite;
The connection is ready and here is the Sample Code:
System.Data.SQLite.SQLiteConnection.CreateFile("sqlite.db3");
using(System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection("data source=sqlite.db3")){
using(System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand(conn)){
conn.Open();
cmd.CommandText = #"CREATE TABLE IF NOT EXISTS
[persons](
[id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[name] VARCHAR(50) NULL
)";
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO [persons] (name) values('Atlas')";
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT * FROM [persons]";
using(System.Data.SQLite.SQLiteDataReader reader = cmd.ExecuteReader()){
while(reader.Read()){
MessageBox.Show(reader["name"].ToString());
}
conn.Close();
}
}
}
Tips:
always use try/catch block for database operations
If you don't prefer to use NuGet Package Manager then you can download library from here
Hope this helps! :)
Does one of these help?
Attach a database file on connect to a local SQL Server Express instance
Server=.\SQLExpress;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;
Trusted_Connection=Yes;
Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;
Trusted_Connection=Yes;

sqlite database location uwp

I have an uwp app with a sqlite database that works as intended; I can close the program and restart it and the database is loaded properly. I want to look at the database with a database viewer but can't locate the file. I have tried unhiding files and searching for db.sqlite. Here is the code that connects to the database:
string path;
SQLite.Net.SQLiteConnection conn;
path =Path.Combine
(Windows.Storage.ApplicationData.Current.LocalFolder.Path,"db.sqlite");
conn = new SQLite.Net.SQLiteConnection(new
SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path);
C:\Users[Your User Name]\AppData\Local\Packages[Your Package Name]\LocalState
Your Package Name: You can find in file Package.appxmanifest in your Project
Your file db.sqlite will in folder LocalState
If you go to
C:\Users\[YourUserName]\AppData\Local\Packages\
your application will have its own folder there, which you may be able to recognise by name or do a search for sqlite, and the SQLite database file should be within your applications folder

Release a WPF app with local database

OK, so I am quite lost. This is my first real application written for windows with a local database.
I have written an WPF application in VS2012 with a local database, which has all CRUD written as stored procedures.
The app is working as I run it in VS. But as I build the app and install it (on any machine) the database is not accessible. I have a feeling the connection string is causing this issue.
First I used this connection string:
SqlConnection conn = new SqlConnection(#"Data Source=(LocalDB)\v11.0;AttachDbFilename='D:\LH\Personalitytest win\DB.mdf';Integrated Security=True;Database=DB")
But as I got "Error: 26 – Error Locating Server/Instance Specified" I guessed that the Data Source of the connection is not correct (although the AttachDbFilename is definitly incorrect). So, I changed the connection string to:
SqlConnection conn = new SqlConnection(#"Server=(localdb)\v11.0;AttachDbFilename=" + AppDomain.CurrentDomain.BaseDirectory + "DB.mdf;Database=DB;Trusted_Connection=Yes;");
And I got an error which basically said that the file DB.mdf is not found.
So, I made sure that the .mdf and .ldf files are copied to the installation directory/database.
But after installation both these files are read only (even if these have read/write persmission as I am developing). I have tried to change the file permissions (for both files) as the application starts for the first time by:
string path = AppDomain.CurrentDomain.BaseDirectory + #"Database\DB.mdf";
FileInfo file = new FileInfo(path);
file.IsReadOnly = false;
and
File.SetAttributes(path, FileAttributes.Normal);
and
FileAttributes attributes = File.GetAttributes(path);
attributes = attributes & ~FileAttributes.ReadOnly;
File.SetAttributes(path, attributes);
but neither of these methods are working.
My question is basically, how should the database be implemented in the final release?
Your database should be located in your windows user directory
Other way is to install SqlServer Express on your machine. And configure your connection string accordingly.

C# using SQlite in project by on user computer it's using a different version?

I am using C# and using sqlite and shipping these files with my program
SQLite.Interop.dll
System.Data.SQLite.dll
right beside myprogram.exe
My Program is installed like this.
C:\Program Files\MyAPPlication\myprogram.exe
I am getting error reports and crashed because the Users Computer is using SQLite from this location
[System.Data.SQLite] System.Data.SQLite.SQLiteCommand : System.Data.SQLite.SQLiteStatement GetStatement(int ) in 'c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs' at Line 314, Column 35
I don't understand why it's not using the version I packed with the program.
In all of my code I am using it like this..
using (SQLiteConnection sqLconnect = new SQLiteConnection("Data Source=" + Class_GlobalVars.StrDbPath + ";Version=3;PRAGMA journal_mode=OFF;"))
{
//code
}
Can anyone tell me why c:\dev\sqlite\dotnet\System.Data.SQLite is being referenced?
Thanks,
Dave
The path specified in a stack trace is not the path where the dll is found, it's the path where the dll was compiled from. It won't match the path on the deployed location (except in development).
Ask a new question with your full exception for help with that. It's not likely related to the location or version of SQLite.

C# SQLite database connection WPF Crash

Hi All hopefully someone can help me.
I have written a small WPF app which reads the password of a SQL database and shows it on screen for the user. It works fine on the SQL DB but we have changed to use SQLite and while it works fine on my machine (on which I hav written the program) but when I give the .exe file to a user the program will crash on them, as soon as they click a button to OpenFileDiaglog() (this is so the user can select the database to retrive the password)
After some trial and error (of commenting out parts of the code) it would seem to crash when it hits this line.
SQLiteConnection Dbcon = new SQLiteConnection("Data Source= " + Myfile);
but in the event viewer on the machine i am trying to run the program on the error is
Description: The process was terminated due to an unhandled exception
Exception info: System.IO.FileNotFoundException
I have tried to use the .exe file on a few different machines (vista, xp, win 7) all of which have the .net framework 4.0 installed on them.
Like I say all works perfrect on my machine only when it is moved does the error come up.
Any help would be greatly appricated
Because yu must adjust your path of your database on user machine, you have false path on your DataSource when you deploy
Data Source= Path of your databse
I suggest you this code
"Data Source=" + System.IO.Path.Combine(System.IO.Path. GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), YourFile)
Same problem but this didn't fix it for me. The problem for me was my main app was in .net 4 and the sql lite dll is .net 2 so add useLegacyV2RuntimeActivationPolicy="true" as an attribute to the startup tag in app.config.

Categories