Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / September 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gambero - 29 Sep 2007 15:14 GMT
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
Ian - 29 Sep 2007 23:08 GMT
> 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,
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.