Entity Framework, Offline Use Strategies? - c#

I am currently learning about EF and have come into a scenario where the data should be used in both an online and offline mode.
It is assumed that the user will have to use the system first while connected to obtain the data used offline.
I thought about serializing the queries but IQueryable/ObjectQuery are not marked as serializable.
How would I go about being able to store results from a few queries locally and then restoring them in offline mode so the use can continue to use the app? I could spend days researching this but I hope somebody can point me in the right direction.
EDIT
It is worth noting that the master SQL Server instance is a shared server that has very minimal features installed. Replication for example, is not installed.

Assuming you are using SQL Server, you vcould take a look at SQL server compact.
http://msdn.microsoft.com/en-us/data/ff687142.aspx
You could copy data from your main DB into a locally stored CE database then switch to this for offline.

Related

Creating and saving a database in my project?

I'm working on a Windows Forms application in VS 2013 that requires saving data. I can't find a good solution for this, since:
A SQL Server database will work fine, but it will force the user
to have SQL Server installed on their computer.
The same applies to Access or Oracle DB.
DataSets require a database connection,which leads me to 1) and 3).
Text/XML files don't satisfy the
security requirements and will seem like a very primitive solution.
So , in essence, when the user installs the application, on its
first deployment it must create a database and keep it for future
access, without requiring the user to have any special programs
installed (e.g. SQL Server). I apologize if this question seems
stupid.
This is in two parts - how to create a database application and how to access it for initialisation.
Option 1 - if you can resolve the problem of installing SQL Lite/compact using the suggestions above then you can use Entity Framework with code first to create the database and tables. There are plenty of examples only a Google search away.
Option 2 - create an Access database (an MDB or ACCDB file) with blank/empty tables and deploy this as part of your application. You can the access this with a suitable connection string - again, Google will solve that one.
Use SQL Compact Edition .
Using LINQ to SQL you can create a Database/Tables for the first time deployment.
Please Refer the Link http://msdn.microsoft.com/en-us/library/bb399420(v=vs.110).aspx

Encrypted database for offline application?

We currently facing the problem to provide an offline version of a Server-Client-App (WCF/Silverlight). On our server we currently working with a heavy weight MSSQL Server, storing global and user data.
Now, to provide an offline version, we have to provide a local database subset. It will have to store a lot of data anyway (probably >6GB).
Now we don't want anyone to be able to modify or even see the db structure and data. But as far as I know, localdb or SQL Express have always the problem, that a local admin with knowledge of sql can open and manipulate the db with sa.
What would your suggestions be?

How to Synchronize SQLServer Database and MySQL Database

My Scenario:
I have two applications. First one is a website which is connected to MySQL Database and 2nd one is a Desktop Application which is connected to SQL Server2008 R2 Database.
The Desktop application updates records locally and the MySQL database is updated online though the website.
Problem:
Two different databases, how can we update at the spot when changes are made either in MySQL or SQL Database?
What I Want:
Databases should be synchronized to each other (e.g. if changes are made in MySQL then SQL server database should be updated, or if changes are made in SQL Database then MySQL database should be updated)
Could anybody please suggest some code, any idea, or any solution to solve this issue?
Make use of Restful API's to Update information from MS SQL server to MYSQL server.
One of the first things I would point out is that complete and perfect syncing is not possible. Unfortunately there will be data types that exist in SQL Server that don't exist in MySQL and vice versa.
But assuming the data types are pretty simple and the schemas are similar, here are some options:
Use a service bus. You can write an application that monitors both database systems and when it sees a change, it pushes an object onto the service bus. Listeners to the service bus will see the objects and write them to the appropriate destination.
Use triggers like Alex suggested. SQL Server can have CLR code execute on a trigger. The CLR code could be some C# that writes directly to MySQL. Takes some setup, but it's possible. I've investigated running a process from a trigger in MySQL and all options are ugly. It's possible, but security is a major concern. The idea is that a record is changed, trigger is fired and an external process is run.
Write an application that constantly looks for "diffs" in tables and moves data back and forth. You'll need to modify all tables to make sure there is support for date/time stamps for each record so you can track when a record has "changed".

Windows Form App - Which database type should I use?

I'm hoping someone can help me. I recently started the development of a windows form application connecting to a remote sql server database. I was happy enough developing it until a potential client queried if they would be able to buy the whole application but they do not want the application connecting to the db via the internet.
I predominantly develop websites using php/mysql but migrated to c# for this particular project. I'm familiar with sql but not sure what database I should be using if the client wishes to have the whole application on their own computer. I've considered providing the database install as a pre-requisite when publishing the app (although I'm currently not sure how to do that) but I'm having reservations whether that is suitable or could lead to more problems. I want to create an application that can install to a single computer and has little to no need for administration. Could someone advise the best way to approach the data storage in this instance.
Because you have already a SqlServer database operating on your remote site, the best path should be to use the LocalDB version of SqlServer Express 2012. See this link about deployment.
If you don't use stored procedures, views and triggers then also the SQL CE could be an option, but you will not have file binary compatibility and you should work on importing your schema and data.
SQL CE is a compact light weight way of going..
http://blogs.msdn.com/b/sqlservercompact/archive/2011/01/12/microsoft-sql-server-compact-4-0-is-available-for-download.aspx

C# SQL Server Express backup and restore

Basically I have a windows form C# program that uses a SQL Server Express database to store data entered by the users. I want to add the ability for the user to be able to backup their database and then load a backup or another database into the programs database.
If someone could point me in the right direction like an article or tutorial that would be great, because I have hit a dead end.
Thanks
You have a few options to do this:
On the server directly call BACKUP DATABASE, RESTORE DATABASE commands.
Use SMO (SQL Server Management Objects) to perform the backup restore operations programatically. (Specifically this sample)
Use some third party utility/library.
You may want to look at using this suggestion:
http://codeasp.net/articles/sql-server/118/backup-your-database-using-an-sql-command-export-to-bak
The nice thing about SQL Server is that you can do more or less everything with SQL (T-SQL or some variation thereof) - this is nice because it means that it is relatively easy to do most things without having to worry about (for example) the availability of SMO and further in a reasonably generic fashion.
The second nice thing is that if you run a command in SQL Server Management Studio (a version of which can be downloaded for SQL Server Express) it will, more often than not (and certainly in the case of Backup and Restore), offer to let you save the the script to a file instead of executing it.
So, it would be straightforward for you to use SQL Server Management Studio to determine the structure of SQL based backu and resotre commands and from there to integrate those into your application.
There is, however, a "gotcha" - SQL server will only save backups to/restore backups from a drive that is visible to the machine & service account upon which the SQL Server instance is running, almost certainly not an issue if your application is running on the same machine as the user but potentially a problem if they are not.

Categories

Resources