Programmatically convert SQLite to .sql - c#

Alright, this will probably sound a bit silly. The more I think about it, the sillier it sounds.
Background:
The company I'm working for hired a guy about a year ago to write some software for them. This software (written in VB6) is for a drilling supplies manufacturer (sensors, bits, etc). Anyway, the software is installed at a rig site, and provides a plethora of information (bit depth, rpms, etc). Now, a reading is taken every 10 seconds, and saved to a file. (I was initially told a local SQL database, but that's proved incorrect.) This file, which can apparently only be opened in SQLite Database Browser (opening it in any text editor results in looking at garbage, essentially).
Move Forward:
I was hired to write a program that takes the data that is saved, and create a daily report based upon it. Initially, I was told that there was a MySQL database on the local machine that is storing the information. However, I just recently found out that that is not the case. It's stored in this file. I can open the file in SQLite Database Browser, and export it as a .sql file, and that is all awesome and such. Problem is, my employer wants this done programmatically.
My Question:
Is there a way to convert this SQLite file to .sql programmatically, or what is the best route to get this information uploaded into a local MySQL database? Thank you for much for any assistance.

Have you considered just using a [the] SQLite data provider for .NET and opening and reading the data out that way? You could easily read the data out of the SQLite database, and the write it into the MySQL database (using the appropriate MySQL data provider).
Here's the SQLite data provider I've used in the past: http://sqlite.phxsoftware.com/ I'm not sure if there's something newer (or better).

Use the SQLite Manager application you have to make an *.sql file dump of the data in the SQLite database. Import the resulting *.sql file into a MySQL database.
Write a C# script that will use this code:
sqlite_db_handler.query('SELECT * FROM dbname.sqlite_master WHERE type='table'');
To get a list of all the tables in the SQLite database.
Iterate over each of these tables and use this code:
sqlite_db_handler.query('SELECT * FROM '+table_name);
Iterate over each of the resulting rows using this code:
mysql_db_handler.query('REPLACE INTO '+table_name+' VALUES('+row.join("','")+')');
Done!
P.S.: It's pseudo-code I'm not a C# developer.

Related

Importing a MS-Project mpp file into C# .Net Framework and exporting the data into an SQLite database using MPXJ

**
Hello
**
I'm creating a scheduling app that takes in 2 MS-Project .mpp files (master and updated) and converts the data into SQLite tables then compares them both and displays the results and allows you to write the changes you make back to the master file. I had issues with Microsoft Interop because I don't own Microsoft Project. Is MPXJ a viable solution? The documentation I've read on it doesn't have many examples. If so how would I read it in and read it back? Were using MS-project 2016
I know nothing of MPXJ, so sorry if I overlook a more straightforward answer. It sounds to me like another way of looking at your problem is you want to:
1. Parse a MS Project file (and then do it again) and store results in memory
2. Do some data manipulation and calculations of the in-memory project data
3. Put that data into a database
I think you're stuck at step 1 because without MS Project, you lack a parser; correct? There are other ways to parse a project file. The simplest may be to have your users first convert the files to a more open format (e.g. XML) when they save them from their instances of MS Project. Lacking that, there are certainly libraries out there that can parse a Project file. Try taking a look at Gantt Project, https://sourceforge.net/projects/ganttproject/ . Being open source, you could look at that parser as a starting point; I'm not a license expert, but you may even be able to re-use the code from there.
Good luck!

Insert row in Clipper .DBF with .NTX

I want to insert data from a old clipper program's database using c#
the database is associated with an .ntx file.
i can insert data using vfpoledb driver to the dbf in my c# program, however, when i look at the old clipper program, the data was not there but it is in the dbf.
the culprit was the .ntx file, it needed to be reindexed so the data would be visible in the clipper program. The reindexing was done by the old program when ever i delete the .ntx files.
how can i insert data and update the .ntx files as well? the old program was not made by me but a past employee here in the company.
You'll need a third-party driver that supports the Clipper .NTX format.
Advantage Database Server from Sybase has .Net data provider, ADO and ODBC drivers that will work, and their local server is free (at least at the time I'm writing this post). The latest versions can be found here. (I'm not affiliated with them in any way; I've just done some porting of old Clipper data.)
The documentation (available both from the downloaded installations and online) contain the entire contents of a commercially published book that contains tutorials and reference materials that will help you get started.
There is a tag for Advantage here, so if you have questions regarding use you can post them using that tag. (Their Data Architect, available from the same site, will let you work with the data and indexes from an IDE as well.)

Importing 2 .txt files to sql server database using asp.net

I have 2 .txt files with data that i need to import to a sql server database in order to continue my project in Visual Studio C#. I was told to use the Stream writer/reader. Can someone explain to me how to use it, and show me all the aspects of how to do it? I am very new.
If you just need to insert the information by hand, you can follow the tips provided here.
If you want to do it through C#, here are some links to get you started:
First you need to parse the text files to retrieve the data. Here's an example on how to do that.
Next you'll need to insert the information. Here's a Beginners guide to doing that.
Good luck!
I have an example here.
http://granadacoder.wordpress.com/2009/01/27/bulk-insert-example-using-an-idatareader-to-strong-dataset-to-sql-server-xml/
It was written for VS2003, but updating it to VS2010 or (or 2008 or other) would be trivial.
It does not use a stream reader. It uses OleDb.
The above is a good solution if you need to do any validations on the data before inserting it.
Here is another idea.
http://www.codeproject.com/Articles/27802/Using-OleDb-to-Import-Text-Files-tab-CSV-custom

backup mysql database and convert it to sqlite to use it in c#

my project manager asked me to do the following:
-backup data from mysql database that is on the server
-convert this data to sqlite
-add it to a windows form application that read from this sqlite new database
the target is to keep part of the database always linked to this c# windows application
I've read articles about backup data from mysql using c# and I don't expect to have problems
backup using mysqldump.exe 1
backup using mysqldump.exe 2
backup using mysqldump.exe 3
How can I convert this mysql dump file into sqlite and load the data to the c# using the sqlite memory and then save it so the application will use this sqlite database each time it runs. All of these steps must be done by the c# windows application itself with a button or something similar.
IMO easiest way to do this, and how we do it: export the tables as CSV. Open them in excel. create an insert statement for the first row in the excel sheet using variables for the cells, append that as an extra column. click and drag that down to repeat that statement on every row.
Copy that generated column, and bring it into your sqlite database browser, and run that huge statement.
the statement should look like : ="INSERT INTO newTable VALUES('" &A2&"','" &B2&"');"
don't make it any harder then it should be :P

Storing and retrieving dynamically created pdf in sql

I have been playing around with creation of pdf documents for a project that I'm working on. I would like to store the generated pdf document in a SQL database and then later be able to retrieve this pdf as well.
What are some suggestions for doing this? Can the document be stored in the database without physically creating the document on the server?
This is again going to bring up the debate for/against storing things on the file system or within sql server itself.
It really depends on your needs, the size that you're expected, etc. Here are some references, each with more references.
Storing a file in a database as opposed to the file system?
store image in database or in a system file?
What are some suggestions for doing
this? Can the document be stored in
the database without physically
creating the document on the server?
Sure just create the pdf as a byte stream (byte[]) and store it in the database. Depending on what you use to create it, you don't have to write it to the file system.
Actually, on the argument about where to store it. If you have SQL server 2008, you want to use that. It will store the file on the file system, but you can access it through the database like you would with any other data. You get the best of both worlds.
Keep in mind that SQL Server 2008 now has the FILESTREAM data type. You can write the data to the file system, yet still store it in a column.
Save the PDF as a byte[] then you can use itextsharp to created the PDF when ready for viewing.
You can use a table like this to store files in SQL Server.
CREATE TABLE [Documents]
(
[FileName] nvarchar(1000),
[FileContent] varbinary(max)
)
You have 2 ways to do that:
Store in FileServer and store the Filename in the database.
Encode file and store in database.
I recomend that you use the second..
why I choose that answer?? for security.
One of a lot of reasons:
A little Example:
If you do the Firt(store the file in the fileserver...) you are
crating a folder on your database.. so you server will be vulnerable
for attacks or for virus..
If you do the second. the file will be encode and store in database
and you dont need to be worried about attacks or machine infections..
I think that this are 1 simple reason about why never use the first WAY!!!!!

Categories