Where does `dbcontext.savechanges()` save data when no connection string - c#

I am working with Microsoft's documentation and learning c#. I am copying an example of databinding with winforms.
The example works, but where is the data stored? I checked my folder, there is no mdf file, and my computer doesn't have SQL Server installed, but when I added something to the table, close the program and reopen it , the data is still there. Where is the data stored?

Related

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

Dumping an SQLite database stored as dll file?

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.

MS Access data base reading in c# .exe project

I have created .EXE setup of C# Data Base (MS Access Data Base) Application using this link Create C# Setup. Actually i have only one windows form in my project where i can INSERT and GET the data from MS Access data base.It retrieves data from data base successful, But when i INSERT some data then prompt error message is displayed,that U can only update the Data Base and can't INSERT new data. I don't know what i have done wrong.
Ok, i got my problem. Actually i had installed my project in drive C:\Program File... which i have made Secure, and no deletion or Insertion in a file inside there can occur. So, what i did, is that i reinstall that new software in other Drive, like D:\ and new it is working well.

.mdf file does not respond to SqlCommand.ExecuteNonQuery

I have a weird problem with my local database. I added it as a .mdf file, and created 2 tables in it.
I tested the connection and the message box states that the connection is working properly.
The problem appears when I try to insert data into that database from my C# application. I tried 2 different ways:
By using SqlCommand.ExecuteNonQuery("INSERT INTO ....")
By using .dbml file (Linq-to-SQL) datacontext
When I try to insert data, no error is thrown, but no data is inserted into the database either. What could be the problem?
I'm using C# in VS 2010 and SQL Server 2005 to make my application
most perceived problems with MDF files tend to boil down to one of:
what file have I actually opened?
is my build/run process actually copying over that file every time I run the application?
do I have gratuitous error-handling that is swallowing an exception?
Check your connection string, and look in the execution folder (not the project folder), until you are very sure which file is being opened. It should get updated after your work (make sure you dispose the connection etc properly).
Also: try fetching the data in a new data-context immediately after the insert, so see if it made it in or not.

Copying the database through the code

I have a database that I connect as a file, i.e. through the AttachDBFile attribute in ConnectionString in web.config file of ASP.NET site. The database is in the App_Data folder od the website. I made a small app, that should allow to copy paste (a kind of backup functionality) the database to any chosen directory. For this I am using FileDialog box for allowing the user to chose the destination directory. I am using the .NET FileSystem API for copy pasting. The problem is that, I cannot copy paste the database till I shut down the SQL Express service. During copy, a dialog saying that the file is currently under use by other process is shown. If I turn off the service I can copy paste the database.
I used AttachDBFile attribute, since I thought that it will allow such copy, since this doesnt directly attach the database to the server. But now I think its not like that. :(
So how I can deal with this. Please help. Thank you.
You get the error since the file is locked while it's in use.
Have a look at the recommended ways to backup your database at msdn: http://msdn.microsoft.com/en-us/library/ms187510.aspx.

Categories