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);
Related
I have a c# application add-on from which I need to validate the schema of a database. I can't use any of the obvious frameworks due to limitations of the application I'm extending, but rather need to find an alternative method to confirm whether database procedures exist and or whether they need to be updated (if the procedure itself was changed from what is expected). Aside from writing individual queries for each procedure are there any better solutions I might consider?
There is database project in visual studio. You can import your database to this project and try to build. Please see official documentation:
https://learn.microsoft.com/en-us/sql/ssdt/import-into-a-database-project?view=sql-server-2017
<twocents>
Export all your objects to .SQL files and commit them to source control and write them out into a folder on disk.
Create a tracker table that maps the object you have exported to a hash of the DDL of the object.
Inspect the objects in the database when your app initialises or at some other appropriate time.
Compare the hash of the DDL of the database object in the database with what is on the disk. If there is a disparity drop and recreate the object by executing the DDL of the file on disk
The hash acts as fast way to check if what's in the database matches the structure of the object that you expect to be in the database. How you deploy it is questionable, but the assumption I am making is that you are in control of your database objects that you have exposed to the application.
</twocents>
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).
I'm developing an app that happens to have some records that need to be updated pretty often. I wanted to avoid deploying SQL Server on the client pc so I read a lot and thought a local .mdf file could be a solution (not so sure now if it's possible to avoid deploying SQL Server, after a few days I'm just realizing I could be miles away from right LOL).
Also, reading, I found there was a way to bind controls to data by visually moving objects from the Data Sources window, so I thought I was going to save a lot of time, but in the end I just got really confused because I couldn't get to actually write to the database file and information currently available seems to be pretty unspecific and works/doesn't for a lot of versions and flavors of VS (i.e. WPF, Windows Forms, vs 2008, vs 2010, and even older .NET framework versions), so I thought someone here in stackoverflow forums might have these things pretty clear.
So, I have some questions I believe will clear out my confusion (and anyone coming across this problem):
Can a .mdf file actually be used without a SQL Server installation?
VS is sometimes confusing, it offers to create a local database file without requiring a SQL Server install, I guess I take a lot of things for granted as I'm not an experienced .NET programmer.
If it's not possible. Is there any other way to avoid deploying SQL Server on the client, and is it a valid concern?
Maybe I shouldn't be worried about not deploying a SQL Server install on the client machine?
Can I get the fancy data bound controls to work with some similar kind of 'automagical' update call that writes changes directly to the database?
There seem to be two ways of managing the database using the app, and, of course, I would like to do it this way and just get those data bound controls to work, as the database is huge and there is not much to process in the way, just store.
Does the DataSet contain a temporal copy of the database?
I have a Database.mdf and a DataSet.xsd and, after searching for reference, I still don't know exactly what's up with these two guys.
No. When you create a new item in your project, the Server-based Database template creates an MDF file and requires a SQL Server Express instance to be installed on all clients.
The Local Database template creates an SDF file, which is a SQL Server CE database. Despite the name, SQL Server CE is a completely different product to SQL Server (Express). SQL Server CE doesn't use a server so you can either install it on the client or just deploy the required DLLs with your app.
Run the Data Source wizard and select your data source. The rest is done for you, as long as you select a supported data source. You can use SQL Server Instance, SQL Server Express File, SQL Server CE or Access out of the box. You can also support Oracle, MySQL and others with downloads from third-party providers.
The MDF is the actual data file, the same as big SQL Server uses to store data. The XSD is the XML schema definition for the DataSet, which is a class like any other. When you retrieve data from the database you use a table adapter, which is an instance of a custom class generated by the Data Source wizard. That table adapter wraps up the standard ADO.NET connection and data adapter objects that you would use yourself if you were not using the wizard. The Fill method of the table adapter populates a DataTable in a DataSet, which are also custom classes generated by the wizard that inherit the standard DataTable and DataSet classes. Once you've made the desired modifications to the data, you call Update on the table adapter to save the changes back to the database. If your controls are bound then populating the DataTable will automatically populate your controls and making modifications in your controls will automatically modify the data in the DataTable.
I want to create a GUI with C++ (QT4). The GUI should work on Windows and should be able to
create a database
use the database created by it (I should use an existing DBMS, in order not to worry for queries)
database should be specific to the GUI, other software should not be able to use that database (the database may be for example encoded)
the gui with its ability of working with database should be easily installed on the other computers, that is I don't won't to ask user to change some options on his computer manually
So my questions are:
What kind of database can help me to do this, what I should learn connected with database to be able to perform this task?
Should I encode the database by my GUI, or databases have such command to save them on disk already encoded?
Thanks!
You could try looking into SQLite. The library can be used with C++. It will not need an external DBMS. SQLite is embedded into your application, and you can access you database through it. Also, the database files it produces can be encoded, so it will be accessible to your application only.
first, you should decide what are the scenario your system going to be applied.
then only proceed to source for database provider (MySQL, Postgres, etc).
you can't really jump to UI implementation straight away because all of the database mentioned above can do what you need.
Complete newbie question here: I'm just playing with C# for the first time and want to make a Windows Forms application which stores some info in a database structure, but obviously don't want to require something like MySQL to be installed on each client's computer. How do I go about this?
You can use SQLite. It doesn't require any installation or server on the client's computers. Here is an blog describing how to use it with .NET. It is easy to use, just add a reference to the System.Data.SQLite.dll.
Here is an open source data provider for .NET: System.Data.SQLite
From homepage: "SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain."
You use a database that doesn't require an install. There are a few out there - there's Microsoft SQL Server Compact, which frankly is badly named, as it won't support the more useful SQL functions like stored procedures, views and so on. There's also VistaDB which does support stored procs, but requires purchase if you want Visual Studio plugins.
The answer is Embedded Databases. You've got quite a large list of Embedded databases that you can use:
Commercial:
VistaDB - This database is written completely in managed C#.
Open Source:
Firebird - .NET Driver
SQLite - .NET Driver
You could write your data to XML files, or you could take a look at the Sql Server Compact Edition.
You could also work with objects and serialize/deserialize these to disk as binaries.
Of course the type of storage you choose depends a lot on the kind of data you're storing (and the volume of it).
Use SQL Server CE
An easy way to do it from .NET 3.5 onwards is to store your data in XML files and use Linq to XML. This allows you to use SQL-like commands on your data which are actually compiled into your application, so you get full IDE IntelliSense support and error checking.
Perhaps you could serialise a dataset and save it as XML. I'm a little confused why if you're playing around you would need to install MySQL on all client's computers. You could look at using SQL Express which is free perhaps?
Serialise Dataset:
http://blogs.msdn.com/yosit/archive/2003/07/10/9921.aspx
http://msdn.microsoft.com/en-us/magazine/cc163911.aspx
The Easiest way will be SQL Server Compact, Because it integrates directly into the Visual Studio IDE (I'm just hazarding the guess here that you use VS). Add the "Local Database", Create your tables and be sure to make your Table Adapter with Select, Update, Insert and Delete methods. If during Database Creation you called your Dataset "DS" you will be able to instantiate a Table Adapter Object from
DSTableAdapters
Namespace, and Use GetData() or Fill() methods to retrieve your Data, and Insert(), Update() and Delete() to Manage it.
VelocityDB works in a server less mode but can also be combined with a server when there is a need for it. It outperforms all the other choices mentioned here by roughly a magnitude, see comparison here. It allows you to use almost any .NET data structures persistently. The entire database engine and the optional server is implemented using C# code.