views:

48

answers:

1

Sorry for my English first of all. I have a problem and need help. I have a simple tool made by myself on c#. This tool makes connect to local or remote firebird server (v.2.5). And my tool can create specified .fdb file (database) somewhere on the server.

Also i have a file with sql-statements (create table, triggers and so on). I want to execute this file after database was created. Executing this file will fill stucture of user database - not data, only structure. But then i try to execute my sql-script - firebird server sends me Sql Error Code = -104 Token unknow line xxx column xxx. Thats lines and columns pointered me on next create-table sql statement, for example:

CREATE TABLE tb1(
col1  INTEGER NOT NULL,
col2  VARCHAR(36)
); 

/* On next create statement will be an error */

CREATE TABLE tb2(
col1  INTEGER NOT NULL,
col2  VARCHAR(36)
); 

If i will leave only one create statement in my file - all will be good... I don't know how i explained (it's clear or not)) - another words - why i can't execute full query with many create statements by one transaction? There is my main method wich executes quiry:

 public static string Do(string conString, string query)
        {
            using (FbConnection conn = new FbConnection())
            {
                try
                {
                    conn.ConnectionString = conString;
                    conn.Open();
                    FbTransaction trans = conn.BeginTransaction();
                    FbCommand cmd = new FbCommand(query, conn, trans);
                    cmd.ExecuteNonQuery();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.ToString());
                    return "Transaction Fail";
                }
            }
            return "Transaction Commited";
        }

There is a query is my sql-file.

+1  A: 

Probably error in launching two create statements in one batch. Would it work if you break it to separate queries? Does it work in your SQL tool?

@Alex this is a common problem with most Databases they don't support more than one transaction in a query. MSSQL requires the use of the `GO` keyword to indicate that another transaction is taking place.
msarchet
Yes, it's will be work, but i don't want to think about engine that takes one file, parsed it, and makes few queries - there is a many bugs i can allow.
Alex
@msarchet - Oh, it's a news for me. Thanks. But, maybe some tricks, some other ways...?
Alex
May be Firebird supports delimiter in a query. Or you could move this to stored procedure (some limitations are possible here too). Or run your batch with some tool like command line sql client or ANT/MAKE/etc.
Found solution - Firebird support script executing. FBScript class (NETProvider-2.5.2) provide it
Alex