Is it possible to create databases programmatically using DBX? - sql-server

Looks like the TSQLConnection only connects to existing databases, and I could not find another component that allows me to send commands to the database server.
I'm using Delphi 2009 with Firebird and MSSQL.
One idea that came was to connect to a system database (master or tempdb in MSSQL for example) and then send create commands to the server. This could be an option for MSSQL, but I'm not sure for Firebird.
I'm also aware of the new DBX metadata in Delphi 2009, but I couldn't find a way to create databases using it. All examples I've found is to modify existing databases.

Yes, you can. dbExpress now includes a powerful set of meta-data classes for doing just that.
Steve Shaughnessy gives a good introduction here.

Erick if you use Devart drivers you can connect without the databasename parameter and send the t-sql create database command.

dbExpress included in Delphi uses a "least common denominator" strategy. Information like query statistics which is available through native drivers is invisible with dbExpress. (Maybe I should ask a question like "Which feature in alternative dbExpress implementations made you switch?")

You can execute "CREATE DATABASE ..." on both databases with standard TSQLQuery.
Note that syntax differes between these two. Since dbx is lightweight lib, this SQL and DB specific action probbably will never be fully supported. It leaves you with SQL.

With Delphi 2007/2009 comes DBX4. You may use the low level structures there to create database programmatically. Look in dbxcommons.pas

You can send a "CREATE DATABASE" script through any connection (ADO, OLEDB, ODBC, etc) opened on any server (or even ms-access files) as long as it follows the specific server DDL syntax.

Related

Remote Link between PostgreSQL and Oracle database

how to create a synonym for a table of a schema in postgresql database on a server into a schema of oracle database on another server?
I have a schema on oracle database on a server and want to create a synonym a table present in a schema of postgresql database on another server.
To create the synonym, we need to have database remote link between these two databases present on two different servers.
How can we do this? Please provide me one solution.
Just to clarify, I believe the question is trying to figure out how to get PostgreSQL data to appear as a table inside of Oracle. (The existing comments seem to be reading it the other way around, in which case, yes, an FDW would be the solution, but in this case that will not work).
In the past (on older versions of Oracle) when we needed this we were forced to build custom replication scripts to transfer data from Postgres into Oracle systems. For a single table, it is pretty straightforward to do with something like Perl & DBI... feel free to substitute that with your favorite scripting language.
On newer Oracle systems, I believe you can use Oracle Database Gateway to accomplish this. I am not sure if they support Postgres directly, but they do support ODBC (and I think JDBC) which should work. Here is an example blog post setting this up with MSSQL (http://oracle-help.com/oracle-database/installation-oracle-database-gateway/), the process should be similar for Postgres.
Hope this helps!

query SQL Server from PostgreSQL

There are SQL Server 2008 R2 and PostgreSQL 9.2 under Windows (currently XP SP3). How can I query SQL Server from PostgreSQL? No problem when SQL Server->PostgreSQL via Linked Server.
Searching web I found odbc_fdw which is not possible to compile for 9.2.
Is there any working solution?
In addition to the standard but immature SQL/MED and foreign data wrappers mentioned by #vyegorov, the traditional solution to this problem has been DBI-Link, a set of foreign data mapping functions that use Perl DBI via plperl.
http://pgfoundry.org/projects/dbi-link/
There is a SQL/MED extension that describes how database can access external data.
PostgreSQL supports this part of the standard via the Foreign Data Wrappers. The linked page describes all (well, almost all I suppose) FDWs that are available now. I think that your finding on odbc_fdw are correct, but I admit, that it is not always straightforward to make FDWs working, especially on Windows.
You can take a look at Multicorn if you're familiar with Python.

What are the simplest database types which I can use with ADO?

I'm looking for a way that I can keep a database in one single file, no server hosting it, and with the ability to use ADO (In delphi, specifically TADOConnection and/or TADOQuery). Please pardon my lack of terminology on this one. I'm only familiar with SQL Server databases, and nothing about any others. In fact, the only other ways I know to read/write files are Plain Text, INI, and XML. As for any official "databases", I know nothing.
So what I would like to do is keep a single file as a database, similar to how QuickBooks has a single "Company File". I should not have anything to host the data, such as SQL Server. And it needs to be compatible with ADO, so I can use simple select, update, delete, etc. It doesn't need to be so complex as to have relations, security, etc. But it does need to have some same syntax rules as SQL Server, like commands such as join, alter, distinct, etc.
I'm looking for the lightest-weight method to do so. The files need to be flexible enough to be able to copy/paste (so long as the application isn't using it), similar to an excel file. In fact, my original idea was to use Excel, as I know I can use ADO, but I also don't want to require Microsoft's excel drivers (it would have to presume that MS Office / Excel is installed on user's computer). It's obviously going to need some drivers, but I need the most standard method which is compatible everywhere.
You can use MS-Access MDB files. It can be used via Microsoft OLEDB Jet 4 engine (Which is build in into Windows since at least Win XP) and is perfect for local desktop DB applications, with the ability to create Tables, PKs, Indexes, Queries/Views, Transactions, Multi-User, replication, compact/repair and much more with almost perfect compatibility to MS SQL-Server SQL syntax (since MS-Access is the ancestor of MS SQL-Server).
MS-Access product (i.e MS Office) dose not have to be installed on the client machine.
No extra drivers or files to install, and completely integrable with existing MS-Office products.
Edit: MDB files could be also Protected/Encrypted.
You have several options for store your data in single database file.
SQLite
Firebird
Interbase
All of them can be accesed via ADO using a ODBC or OLEDB driver. my personal recomendation is Firebird, because is free, fast, stable and had a Embedded version.
This is a pretty useful comparison of a number of embedded databases. Of the ones tested these ones support (odbc), (oledb) or (both) and use a (single) file for the database:
Accuracer (odbc) (single)
NexusDB (odbc) (single v4 and newer)
Firebird (both) (single) - multiple odbc implementations and the commercial IBProvider supports three different ways to connect to the ADO components.
TurboDB (odbc) (single v4 and newer)
Note: Most of these also supply ADO.Net Providers as well.
The other's in the comparison (Advantage, ElevateDB, DBISAM and Apollo) use a file per table/index scheme.

Execute querys to DBF files on SQL Server

As I've posted on this thread I need keep synchronized an SQL Server (not only SQL Server, if you recommend another server which do the same thing) and VFP DBF tables to use on the systems of the company.
As #alex-k said, Linked Server doesn't support INSERT, UPDATE nor DELETE but I need the CRUD statements to the systems work. I've already tried the suggestion of #alex-k but returns error.
As a lot of things in computation has more than one way, what do you recommend to my situation?
Thanks.
I've actually just installed SQL2008R2 on an old machine. Successfully created a linked server and tried the update direct from within SQL. Ran into your same error that it won't work. So, I looked around too and found something on "tek-Tips" forum that descdribed opening a rowset to apply an update via this link
When trying that, I got a follow-up error listed below.
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
Since I don't want to open up features regarding security, even on a machine just for sample purposes, you might be more open to enabling/disabling this feature and trying the suggestion from tek-tips...
Good luck otherwise.
Today DBF files are not widely supported. As far as I know Microsoft Access still supports dBASE DBF files which should be compatible with VFP DBFs.
You can build some kind of gateway in MS Access responsible for synchronizing VFP and SQL Servers databases.
I have not used them since their pre-apollo days (uit sed to be called successware or SDE), but this company might have something that will help. The problem you are going to encounter with other solutions that can read-write the dbfs is that they might not be able to keep the index files up to date (cdx, ndx, etc). If they don't have a driver that helps, you might have to resort to creating an extended stored procedure to natively call their interface. Hopefully you won't have to resort to that.
-don
Have you considered building a small Visual FoxPro application to do this. Visual FoxPro can read and write to both SQL Server and DBFs. We have done this numerous times. The key is to understand what records have changed, and using surrogate primary keys on both sets of data.
Rick

migrate data from MS SQL to PostgreSQL?

I've looked around and can't seem to find anything that answers this specific question.
What is the simplest way to move data from an MS SQL Server 2005 DB to a Postgres install (8.x)?
I've looked into several utilities like "Full Convert Enterprise", etc, and they all fail for one reason or another, ranging from strange errors that make it blow up to inserting nulls rather than actual data (wth?).
I'm looking at a DB with all table except for a single view, no stored procs, functions, etc.
At this point I'm about to write a small utility to do it for me, I just can't believe that's necessary. Surely there's something somewhere that can do this? I'm not even too worried about cost, although free is preferable :)
I don't know why nobody has mentioned the simplest and easiest way using robust MS SQL Server Management Studio.
Simply you just need to use the built-in SSIS Import/export feature. You can follow these steps:
Firstly, you need to install the PostgreSQL ODBC Driver for Windows. It's very important to install the correct version in terms of CPU arch (x86/x64).
Inside Management Studio, Right click on your database: Tasks -> Export Data
Choose SQL Server Native Client as the data source.
Choose .Net Framework Data Provider for ODBC as the destination driver.
Set the Connection String to your database in the following form:
Driver={PostgreSQL ODBC Driver(UNICODE)};Server=;Port=;Database=;UID=;PWD=
In the next page, you just need to select which tables you want to export. SQL Server will generate a default mapping and you are free to edit it. Probably you`ll encounter some Type Mismatch problems which take some time to solve. For example, if you have a boolean column in SQL Server you should export it as int4.
Microsoft Docs hosts a detailed description of connecting to PostgreSQL through ODBC.
PS: if you want to see your installed ODBC Driver, you need to check it via ODBC Data Source Administrator.
Take a look at the Software Catalogue. Under Administration/development tools I see DBConvert for MS SQL & PostgreSQL. Probably there are other similar tools listed.
You can use the MS DTS functionality (renamed to SSIS in the latest version I think). One issue with the DTS is that I've been unable to make it do a commit after each row when loading the data into pg. Which is fine if you only have a couple of 100k rows or so, but it's really very slow.
I usually end up writing a small script that dumps the data out of SQLServer in CSV format, and then use COPY WITH CSV on the PostgreSQL side.
Both those only take care of the data though. Taking care of the schema is a bit harder, since datatypes don't necessarily map straight over. But it can easily be scripted together with a static load of the schema. If the schema is simple (just varchar/int datatypes for example), that part can also easily be scripted off the data in INFORMATION_SCHEMA.
Well there are .NET bindings for MS SQL Server 2005 (obviously) and also for PostgreSQL. So it would only take a few lines of code to code up a program that could transfer data safely from one to the other. The view would probably have to be done manually as Postgres doesn't use the same language for views as SQL Server.
This answer is to help summarize current connection string because someone may overlooked the comment.
Current version of ODBC connection string is:
For 32-bit system
Driver={PostgreSQL UNICODE};Server=192.168.1.xxx;Port=5432;Database=yourDBname;Uid=postgres;Pwd=admin;
For 64-bit system
Driver={PostgreSQL UNICODE(x64)};Server=192.168.1.xxx;Port=5432;Database=yourDBname;Uid=postgres;Pwd=admin;
You can check the driver name by typing ODBC in windows search.
And open ODBC Data Source Administrator

Resources