The type of the SQL statement could not be determinated

送分小仙女□ 提交于 2019-12-13 02:08:41

问题


When I'm trying to execute following query

<!-- language: sql -->

    CREATE TABLE STUDENT (
    ID INTEGER NOT NULL PRIMARY KEY,
    NAME VARCHAR(255) NOT NULL
    );

    CREATE GENERATOR GEN_STUDENT_ID;

    SET TERM ^ ;
    CREATE OR ALTER TRIGGER STUDENT_BI FOR STUDENT
    ACTIVE BEFORE INSERT POSITION 0
    AS
    BEGIN
       IF (NEW.ID IS NULL) THEN
       NEW.ID = GEN_ID(GEN_STUDENT_ID,1);
    END^

    SET TERM ; ^

I'm getting the error "The type of the SQL statement could not be determinated"

This script is running by c# code

FbConnectionStringBuilder csb = new FbConnectionStringBuilder();
csb.ServerType = FbServerType.Embedded;
csb.Database = "mydb.fdb";
csb.UserID = "SYSDBA";
csb.Password = "masterkey";

string conString = csb.ToString();
FbConnection.CreateDatabase(conString);

FbScript script = new FbScript("DB_GEN.sql");
script.Parse();

using (FbConnection conn = new FbConnection(conString))
{
    conn.Open();
    Console.WriteLine("Connection opened");

    FbBatchExecution fbe = new FbBatchExecution(conn);

    foreach (string cmd in script.Results) {
        fbe.SqlStatements.Add(cmd);
    }

    try {
        fbe.Execute();
    }catch(Exception e) 
    {
        Console.WriteLine(e.Message);
    }

    conn.Close();

    Console.WriteLine("Connection closed");

    Console.WriteLine("Press any key to continue . . . ");
    Console.ReadKey(true);
}

I'm using Firebird Embedded v2.5.1 and FirebirdSql.Data.FirebirdClient v2.7.0.0


回答1:


Got the answer from another site. It appears there was need to replace this line

FbScript script = new FbScript("DB_GEN.sql");

by this

StreamReader sr = File.OpenText(@"C:\TEMP\DB_GEN.sql");
FbScript script = new FbScript(sr.ReadToEnd());

Script was run correctly!



来源:https://stackoverflow.com/questions/9259034/the-type-of-the-sql-statement-could-not-be-determinated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!