Unix Technical Forum

[Newbie question] Create database error using IBM .NET data provider

This is a discussion on [Newbie question] Create database error using IBM .NET data provider within the DB2 forums, part of the Database Server Software category; --> Hi, i'm very newbie in db2 databases... i have to create a database via c# code on windows machine... ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 02:06 PM
Gambero
 
Posts: n/a
Default [Newbie question] Create database error using IBM .NET data provider

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=SystemAcco unt;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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 02:06 PM
Ian
 
Posts: n/a
Default Re: [Newbie question] Create database error using IBM .NET data provider

Gambero wrote:

> DB2Connection conn = new DB2Connection();
> conn.Connection =
> "Server=MachineName;Database=SAMPLE;UID=SystemAcco unt;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!


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,





Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:38 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com