问题
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