I currently have a database connected to ODBC using the DBISAM 4 ODBC Driver.
I need a way to convert this database into an .MDB access database file using code.
I suggest doing it in 2 steps:
Conversion of database schema. In this step create SQL file with CREATE TABLE commands with info from your database source. Some data types may be different in your source and it may be hard to convert it to MS Access. Try to run such SQL commands on MS Access and correct errors until your schema looks identical (the same names of tables and columns, identical or very similar data types).
Copy data. Now you have identical or very similar schema on both sides. Now export source data to destination table. There are many ways of doing it. I prefer Jython with JDBC drivers, PreparedStatement with INSERT and code that looks like:
insert_stmt.setObject(i, rs_in.getObject(i))
This will work with ODBC while in JDK 1.7 and earlier there is JDBC-ODBC bridge (it disappeared in JDK 1.8). I think that in .NET environment it is very similar.
Related
I have a file called xxx.h2.db
My goal is to be able to execute queries in order to delete/edit records (preferably in a C# application).
DBeaver
I have tried opening the file with DBeaver using the H2 embedded option. This results in 2 schema's:
INFORMATION_SCHEMA
PUBLIC
Unfortunately the public schema has no tables.
I wasn't expecting this result considering the filesize is around 150mb.
When opening the database i've noticed that it creates two more files in the H2 database's directory:
xxx.h2.db.mv.db
xxx.h2.db.trace.db
C#
While trying to use an ODBC driver as mentioned in this article: https://wiki.postgresql.org/wiki/Using_Microsoft_.NET_with_the_PostgreSQL_Database_Server_via_ODBC
i came across this step, in which i'm unsure what information to enter.
Image of ODBC datasource administrator
Once you've installed the ODBC driver you will need to add a new user
data source. This is achieved by going to 'Control Panel', 'Admin.
Tools', 'Data Sources (ODBC)'. Then selecting 'Add User DSN'. [NOTE:
These names and locations may vary slightly with different Win OS's.]
Select the PostgreSQL driver, and fill in your server and database
details. You must also specify a unique DSN name; in Windows 2000 this
field is, confusingly, labelled 'Data Source' in the data entry dialog
box and not 'Data Source Name' which would be more appropriate. It is
this name that you will later use in your programs to specify which
database connection you want to use. Of course you can have as many
User DSN entries as you want for different databases, servers and
users.
Questions
Why can't i see any public tables in DBeaver?
Am i on the right track to get it working trough ODBC? Which information should i enter?
Thanks
It looks like you included file name extension into connection URL (xxx.h2.db), but you need to specify path to database without extension (xxx).
Please also note that .h2.db extension belongs to old storage engine (PageStore), it is still supported, but it has some limitations.
Additionally you need to make sure that you use the same version of H2 as it was used to create the database file you have, usage of different version may lead to its corruption.
Connection to H2 through ODBC with ODBC driver for PostgreSQL is experimental only, it may not work at all. There were some improvements in this area since the last release, but it's not a reliable thing even with H2 compiled from its current sources. Also ODBC connections with this driver now use PostgreSQL compatibility mode of H2, so they can be not really compatible with your existing database. You can also try to use some third-party (possibly commercial) bridge to JDBC for .NET instead of that functionality.
I have an Oracle database with a table Customers to which I only have read-only access. I would like to copy some columns from this table and insert them into a SQL Server 2008 R2 table called Customers, only when the ID does not exist in the destination table.
I'm new to C#.... I can open and read from Oracle successfully using Oracle.DataAccess and I can write to SQL Server, but I am lost on how to read from Oracle then write into SQL Server. All the examples I could find are for databases of the same type.
I wanted to follow up on this to share that despite many creative solutions offered here and elsewhere, there was not an efficient enough way to accomplish this task. In most every case, I would have to read the entire contents of two very large tables and then check for missing records without the performance advantage of a true join. I decided to go with a hybrid model where the app obtains basic information from the main Oracle database and then reads and writes the supplemental information in and out of SQL Server.
I have an application that reads from an SQL Server CE 4.0 database file.
The user has the option on startup to choose a database. Each database has the same schema, but different data.
Given that I want to ensure that they dont use an invalid database (or point the app at a word file or something), Is it possible to validate the schema of a selected database?
In the past I have used ADO.net to check that each column in each table exists but this seems dreadfully silly when entity framework is there. surely there must be something in EF that performs this, but I cant find it.
I am looking for an answer more sophsticated than "Run a query and if it fails then the database is invalid" as there could be many other reasons why such a query would fail
There is no functionality in EF to do this.
You can use my SQL CE Scripting API, available via NuGet http://www.nuget.org/packages/ErikEJ.SqlCeScripting/
First use
DataSet GetSchemaDataSet(GetAllTableNames());
And save it and add to your app.
Then use
DataSet GetSchemaDataSet(GetAllTableNames());
on the loaded database
Then compare the two DataSets
DataSet dsDifferences = new Dataset();
dsOriginal.Merge(dsChanged);
dsDifferences = dsOriginal.GetChanges();
(If dsDifferences has tables with rows, then there were differences)
My library also has a method DetermineVersion(string fileName) to check if the file appears to be a valid SQLCE file.
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
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);