Hi, i'm very newbie in db2 databases... i have to create a database via c#
code on windows machine...
if i create database via control center command editor "create database
mydatabase" it's work fine!
the problem is create it throught c# code...
first: the connection string? i have to connect to a "master" database that
allow me to create other databases? (like sql server)
my test was connected to SAMPLE database:
using IBM.Data.DB2;
DB2Connection conn = new DB2Connection();
conn.Connection =
"Server=MachineName;Database=SAMPLE;UID=SystemAccount;PWD=Password";
conn.Connect();
DB2Command cmd = new DB2Command("create database mydatabase",conn);
cmd.ExecuteNonQuery();
the error of cmd.ExecuteNonQuery() is (translated from italian):
ERROR [42601] [IBM][DB2/NT] SQL0104N found unexpected token "database" after
"create". expected tokes can be "TABLESPACE". SQLSTATE=42601
it's sound like syntax error... but same sintax in control center command
editor work fine!
Anyone can help me?
Thanks
> DB2Connection conn = new DB2Connection();
> conn.Connection =
[quoted text clipped - 10 lines]
> it's sound like syntax error... but same sintax in control center
> command editor work fine!
This is a very common mistake for DB2 newbies! 'create database' is a
command, not an SQL statement. There are many other such commands, such
as 'import', 'export', 'load', 'runstats', etc.
So you can't do this via C#, without writing code that calls the
appropriate C API. 'create database' is exposed in the sqlecrea() API
call.
Good luck,