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... ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| ||||
| 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, |