6

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.

Erick Sasse
  • 2,779
  • 3
  • 24
  • 30
  • Whatever is the framework you use, you can create a database on a Relational Database Server by sending plain text DDL instructions to this server. It works with MSSQL, and it works with Firebird too – Philippe Grondier Dec 30 '08 at 20:28
  • see similar question http://stackoverflow.com/questions/423808/creating-a-database-using-dbexpress-in-delphi – stukelly Jan 09 '09 at 22:06

6 Answers6

3

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

Steve Shaughnessy gives a good introduction here.

Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
Nick Hodges
  • 16,902
  • 11
  • 68
  • 130
  • 1
    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 Dec 31 '08 at 11:56
0

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

Diego Garcia
  • 1,134
  • 1
  • 12
  • 25
0

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?")

mjn
  • 36,362
  • 28
  • 176
  • 378
-2

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
  • 3,448
  • 1
  • 18
  • 24
-2

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

user114285
  • 513
  • 7
  • 19
-3

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
  • 10,900
  • 3
  • 33
  • 72