Transferring existing MySql database records to SqLite - c#

I've been searching the net for quite a while but haven't found a appropriate method to accomplish my task.
My goal is to set a local database for windows phone 8. The problem is that I have a lot of data and moreover, lot of tables(15) which are logically "all" connected. I've seen numerous methods on how to build a local database but I think that it would take ages to write all of this classes(events, properties, reflection,asyncs...) and connect all of my tables writing c# code manually.
What I would like is to transfer my Mysql database records to SqLite and somehow store this database locally on wp8.
Is such thing possible in a short time or must I built the entire database and insert all data one by one using c#.

The fastest way to do this is with a ETL tool ( Extract, transform, load tools ).
I highly recommend Pentaho Data integration and Business Analytics, it has an open source version, the one I am putting on this link, and a paid one.
It is very intuitive to use. Just select the source ( in your case a mysql database ), use the transformation tools you need ( data integrity check, relationship check, etc ) and finally select your destination ( a sqlite file).

Related

Copy data between two SQL Server databases in C#

I have two databases. One of them belongs to a CRM software and is the source.
The other one will be the destination used by a tool I'm developing.
The destination will contain a table ADDRESSES with a subset of the columns of a table of the same name in the source database.
What is the best (most efficient) way to copy the data between those databases (btw: they're on different SQL Server instances if that's important).
I could write a loop which does INSERT into the destination for each row obtained from the source but I don't think that this is efficient.
My thoughts and information:
The data won't be altered on its way from source to destination
It will be altered on its way back
I don't have the complete structure of the source but I know which fields I need and that they're warranted to be in the source (hence, access to the rows obtained from source isn't possible using the index of columns)
I can't use LINQ.
Anything leading me in the right direction here is appreciated.
Edit:
I really need a C# way to copy the data. I also need to know how to merge the copied rows back to the source. Is it really necessary (or even best practise) to do this row after row?
Why write code to do this?
The single fastest and easiest way is just to use SQL Server's bcp.exe utility (bcp: Bulk Copy Program).
Export the data from the source server.
Zip it or tar it if it needs it.
FTP it over to where it needs to go, if you need to move it to another box.
Import it into the destination server.
You can accomplish the same thing via SQL Server Management Studio in a number of different ways. Once you've defined the task, it can be saved and it can be scheduled.
You can use SQL Server's Powershell objects to do this as well.
If you're set on doing it in C#:
write your select query to get the data you want from the source server.
execute that and populate a temp file with the output.
execute SQL Server's bulk insert statement against the destination server to insert the data.
Note: For any of these techniques, you'll need to deal with identity columns if the target table has them. You'll also need to deal with key collisions. It is sometimes easier to bulk load the data into a perma-temp table first, and then apply the prerequisite transforms and manipulations to get it to where it needs to go.
According to your comment on Jwrit's answer, you want two way syncs.
If so, you might want to look into Microsoft Sync Framework.
We use it to sync 200+ tables on Premise SQL to SQL Azure and SQL Azure to SQL Azure.
You can use purely C#. However, it might offer a lot more than you want, or it might be over kill for a small project.
I'm just saying so that you can have different option for your project.
If these databases exist on two servers you can setup a link between the servers by executing sp_addlinkedserver there are instructions for setting this up here. This may come in handy if you plan on regularly "Sharing" data.
http://msdn.microsoft.com/en-us/library/ff772782.aspx
Once the servers are linked a simple select statement can copy the rows from one table to another
INSERT INTO db1.tblA( Field1,Field2,Field2 )
SELECT Field1,Field2,Field2 FROM db2.tblB
If the Databases are on the same instance you only need to execute similar SQL to the above
If this is one time - the best bet is normally SSIS (SQL server integration services), unless there are complex data transformations - you can quickly and easily do column mappings and have it done (reliably) in 15 mins flat......

Options for working with two databases in C#

Ok I`m new to C# and new to Programing. I have taken on a small task(goal) for writing my own program for work.
Basically this program will take two databases. One data base will be update weekly (lets call this doctor list) and the other data base will be updated as needed (lets call this employee).
Basically I want to make my program compare the two databases and look for any matching employees on this list doctor list.
I can figure out the code for the searching and basic stuff.. But I have no clue where to begin with databases.
I'm ok with SQL but my problem is that my doctor list comes in a dbf file. I've looked up converting to access and sql but this program needs to be easy to use for our hr department.
Is there away to write the conversion? (again new to this)
What kind of options do I have with just working with programing it to read off an excel sheet?
If I do go the access or sql route do the computers this program run off of need to have access or sql installed?
I`m not looking for someone to write me the code.. just point me in a good directions and answer some questions...
To convert the database to SQL you'll need a third party application.
I'd check out: http://www.whitetown.com/dbf2sql/ because it includes the DLLs for use in your application as well when you buy the site license. If you're receiving a new database each time and need to transform it, that would be the way to go.
Your client should be the one accessing the database, which should (hopefully) be stored on a server. If it's a local database (so not multiple user based) then I'd recommend going SQLite as it's probably the best lightweight standalone database out there. You can also get a good ORM for SQL or SQLite (such as DrivenDB) to be able to access your data.
If you're going to stay in dbf format then you'll need to know if it's a VisualFox Pro, Dbase, etc. type of database and get the appropriate DLLs for accessing it.

How can I store a lot of data locally for a program

I am current building (in C#) a fairly basic point-of-sale program for a local community in Uganda to use in tracking business at their sunflower seed press. I was thinking that I would need some sort of database (like a SQL database), but I've never set up a database before, so I'm wondering what the best way to do this is. Maybe a database isn't the best way. The program will not have internet access, so everything will have to be done locally on the machine.
I think your first step should be designing out what data you need to store. Build an Entity Relationship Model and decide what your domain model is going to be. There are many different Database Engines out there that you can use that have different features, installation requirements, etc. A database engine can be installed locally, or on a remote machine to connect to. If you're writing a C# app, you'll probably want to use the System.Data namespace. You can use plain ADO .NET, or use something like Linq To Enttiies to help create proxy classes for your data tables.
You can access a SQL database using the same API for queries / record extraction regardless of the DB Engine uses. In some caess, you may need to use a seperate library that provides an implementation (or a better one), as in the case of an Oracle Database and the Oracle Data Access Components. Right out of the gate, .NET works very well with Microsoft SQL Server, but other options would work.
The details of what database engine are not as important as defining a good set of data tables to represent your data.
Yes. If it has lots of data you have to consider using database. Whether you have internet or not, as long as you have local network, you can easily do database.
Set up a database server ( maybe sql)
Do your database and install it on the database server
Do your application and connect to your database through connection string.
You are on the right track to use a database to store data. It is pretty easy to accomplish. Your computer does not need to be connected to the internet.
SQL Server Express Edition is free with a limit of 10 gigs of data. This will probably be much, much more space than you will need.
From C#, use ADO.NET. It is very simple if you know some SQL. Code samples here.

How to programmatically extract SQL Server table schema to construct SQL Server CE?

As stated in the title, how can I programmatically create a SQL Server CE 4.0 from a remote SQL Server?
I want my application to allow users to delete the .sdf and create a new one based on the new remote database schema when there is a database schema update. And then download relevant data for offline use.
I already read up about the SqlCeEngine part, but I am not good at SQL Server CE queries - seem to give many syntax errors when trying out in Management Studio.
I also tried Microsoft Sync Framework Snapshot synchronization but it feels too bulky and the Local Cache Database modifies my database schema and generates a lot of junk I do not need. Maybe a lower level solution like querying information.schema or something may work better?
Checkout DMO. Using managed code, you can enumerate objects like tables, columns on the sql server side.
http://msdn.microsoft.com/en-us/library/aa174487(v=sql.80).aspx
Here's a tutorial to get you started:
http://www.codeproject.com/KB/database/SMO_Tutorial_1.aspx
Concerning the data, one option is the bcp utility
http://msdn.microsoft.com/en-us/library/aa337544.aspx
Those are good starting points if you want to extract and create a new database. For mirroring/sync, probably not a good path. If it's read only data on the client and you jst want to update the local data, then you can just extract again and throw away the old 'data cache'
You can use my scripting API and command line tools to do this: http://exportsqlce.codeplex.com - see for example this blog post: http://erikej.blogspot.com/2010/02/how-to-use-exportsqlce-to-migrate-from.html
This may be a more up to date way using SQL only:
SELECT * FROM INFORMATION_SCHEMA.COLUMNS

Embedded (In memory) database or Stand-Alone Database

I will build an C# WPF application that intakes USB/RS232 data (~ rate: 10ms) for hours and have to store all these data to a database. User can save all the RS232 data and setting data (e.g. TextBoxes) to a database and also output them to a file. Once they output all the data to a file, the corresponding data in the database will be erased. The user can later, import (or open), the file and load it into the application, and all its data will shown on the display and store back to the database again. I am looking for embedded database solution where user does not need to install a database server separately.
Can embedded (in memory) database, such as SQLite, accomplish such a job?
Yes SQLite can do this - there are a couple of points specific to your situations:
In order to use an in-memory database you must specify :memory: as the data source on your connection string.
In order to copy the in-memory database to disk you must use the SQLite backup API (see this question for more details) - these are not exposed by the System.Data.SQLite data adapter (the one I recommend you use), and so you will need to craft yourself some PInvoke calls.
Why not? There is now SQL Compact Edition 4 with Visual Studio 2010.
SQLite does not require installation of a database server. It can also operate in-memory: http://www.sqlite.org/inmemorydb.html
For using C# with SQLite, see: Is there a .NET/C# wrapper for SQLite?
SQLite doesnot require any installation but developing according to SQLite is cumbersome.
For example, even above statement gives error.
CREATE TABLE IF NOT EXISTS firma (firm_id INTEGER PRIMARY KEY,firm_name TEXT,firma_owner TEXT,counter INTEGER);

Categories