无法确定SQL语句的类型 [英] The type of the SQL statement could not be determinated

查看:147
本文介绍了无法确定SQL语句的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试执行以下查询时

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 ; ^

我收到错误消息无法确定SQL语句的类型"

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

此脚本通过c#代码运行

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);
}

我正在使用Firebird Embedded v2.5.1和FirebirdSql.Data.FirebirdClient v2.7.0.0

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

推荐答案

从另一个站点获得答案.似乎有必要替换此行

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

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

以此

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

脚本运行正确!

这篇关于无法确定SQL语句的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆