How to protect ado.net entity generated database on a local machine - c#

I have a C# application in .net 3.5 using SQL Server 2008 R2.
I am using ado.net Entity Framework to generate the database but after generating it when I remove the database file from SQL Server the framework does not generate the database.
I want to generate database on users local machine while installation and have a password on database access and protect the data from being read or modified by a local user rather than my application.
So the question is how to achieve this with out encrypting the whole data?
What is the parallels here?

I don't think EF in .NET 3.5 was ever capable of creating a database at runtime.
You'll have to either upgrade to .NET 4 and EF 5 or 6 to use code-first with migrations to handle this, or then you need to write some code to handle that situation yourself, in .NET 3.5.
Also: a SQL Server database (file) doesn't have a password mechanism like Access or other file-based system do. Access to a SQL Server database is handled by the SQL Server itself by means of logins on the server, users on the database-level and permissions for those users.

Related

asp.net mvc Load Database from .mdf file

I'm building an Web App using MVC, using Entity Framework.
Usually, the entity framework takes data from the database from the MSSQL server installed on machine.
I want to make at login a check, for example, if the connection at database is ok, if not, to take a .mdf file (stored on a cloud server) and use the data from that db.
This will be the 'emergency' database, backup etc.
Is this possible?
You can use DbContext constructor that takes connection string to the database. That's how you can handle to which DB you will connect.

Store data in local DB using C# Windows Application and make local DB hidden from user

I want to create a C# windows application and store data in a local Database like SQL Express (or any other local DB). Then I want to make local DB inaccessible directly by user and data should be reached only by windows application.
In other words I need something like "Isolated Storage" functionality but for storing larger volume of structured data in a relational database.
This is a difficult question to answer fully without more details but there are some options for you to try:
the easiest route would be to install SQL server locally and use the Transparent Data Encryption feature but this is available only in the Enterprise Edition (which means a pricier license)
SQL Server LocalDb cannot be encrypted and I believe its password protection can be easily bypassed if someone can access the database file
SQLite databases can be password protected to avoid anyone not knowing the password accessing them
There are some extension to encrypt a SQLite database but most of them require a license. You can see this answer for more informations
There is a three level of security you can do it like the below :
1. Add username and password to you db
2. most of embedded Db have an own security level
3. use System.Security.Cryptography to protect your data
And There is many options of embedded database to use :
SQLite Db which have a ADO.NET provider You can use it with SQLCipher is an open source extension to SQLite that provides transparent 256-bit AES encryption of database files.
LiteDB it is an open source, cross-platform serverless database delivered in a single DLL (less than 200kb) fully written in .NET 3.5 C# managed code also supported
Firebird it is a free, open-source database and supported by Ado.Net

Using Entity Framework 6 with MySQL

I've been trying to connect to a MySQL database which is hosted on a RaspberryPI and I have been having a lot of trouble and wanted to know if it is possible before I continue.
I want to use .Net's Entity Framework 6 on Visual Studio 2013 in the same fashion as you would SQL Server to create Entites from the Database. First of all is this possible?
I have had two problems so far:
Firstly, I have been able to connect to a MySQL database on my local copy but not the Raspberry Pi's even though I have a user which allows any IP and has most privileges (I am connecting through LAN).
My Second problem is that once I have accessed and picked a database I receive this error, which makes me think that Entity Framework doesn't support MySQL:
I am also having a problem logging into my local instance of MySQL when the user has a password, which makes me think this could also be why I can't login to the remote MySQL?
You'll have to use an EF Provider to use MySQL and Entity Framework together. Some older Providers don't work with EF at all, or only previous versions.
Connector.NET is the 'official' solution: http://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
There is also some tooling from Devart (DotConnect) that may work 'better' than the MySQL Connector.NET. The reason I say that is in my experience Oracle's EF Provider (For Oracle) was not nearly as easy to set up / maintain as the Devart Solution.

Where does code first entity framework save data

Ok so i know I'm fairly new to C# and MVC but I'm trying to use the code first approach of adding items to a database.
Now I have successfully created new entries to the database but when I go to SQL Server i cannot find the database or tables.
So my question is where is this data being stored as I can't see it in SQL Server like my other databases that I manually created?
My ConnectionString is:
Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Testing-20140809020449.mdf;Initial Catalog=aspnet-Testing-20140809020449;Integrated Security=True
LocalDb is the new server-less version of SQL Server that has similar features as SQL Express. I would describe it as a just-in-time version of SQL Server that is only running when needed.
In order to connect to it usng SQL Server Management Studio, you need to connect using the following connection string (assming SQL Server Version 11/2014 may change to 12 or higher in future versions):
Then you'll have access to the database.
[project_dir]\App_Data\aspnet-Testing-20140809020449.mdf

Linq-to-SQL (dbml) with Local database cache (C#+VS2010)

I'm developing a WPF application, which connects MS SQL2008 database remotely.
The app communicates with the database by Linq-to-SQL. pretty handy.
However, because of the slow database server, I'm trying to use local database caching.
"VS2010 > Add Item > Local database cache" wizard could be a solution, but it uses DataSet and SQL Compact(*.sdf).
I found Linq-To-SQL cannot generate classes from the SQL COMPACT edition!
(when I drag tables, error pops up and says 'unsupported data provider')
So, is there any solution to use Linq-to-SQL with local database cache?
or is there any database sync method played with Linq-to-SQL?
If you still want to go the sql compact way, Lightspeed is a linq-to-sql provider that supports a variety of data-sources. it includes mssql compact.
http://www.mindscapehq.com/products/lightspeed
The free version is sufficient for most projects, with an 8 model/class limit.
Ive used it as a linq provider for MySql and Sql Compact before and it's been great.
You can see everything it supports and how it compares to other existing systems like it here:
http://www.mindscapehq.com/products/lightspeed/comparing-lightspeed
the Local Database Cache Wizard only supports SQL Ce on the client side. if you have SQL Express/SQL Server on the client side, you can use Sync Framework still.
see following samples/tutorials using Sync Framework:
Synchronizing SQL Server and SQL Express
Database Sync:SQL Server and SQL Express 2-Tier
nevermind if it mentions SQLExpress, the SQLSyncProvider referenced in the code should work against SQL Express,SQL Server, and SQL Azure

Categories

Resources