views:

620

answers:

4

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.

A: 

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.

dmajkic
TSQLQuery database requires a connected TSQLConnection.
Erick Sasse
Yes. SQLServer: Connect to master database, create your neew database, then connect to it.
dmajkic
A: 

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.

Philippe Grondier
I'm asking about using the DBX framework, not others.
Erick Sasse
+3  A: 

Yes, you can. dbExpress now includes a powerful set of meta-data classes for doing just that.

Steve Shaughnessy gives a good introduction here:

http://blogs.codegear.com/steveshaughnessy/2007/09/07/38810

Nick Hodges
I'm aware of the new DBX metadata, but there is no way to create databases using it. At least I can't find. If you could give me a example. All I'm able to do is modify existing databases.
Erick Sasse
A: 

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

You are talking about DBX metadata. Look at my comment on Nick Hodges answer.
Erick Sasse