fbScript.Parse() 中的 FirebirdClient 5.7 ADO.NET UnknownStatement

FirebirdClient 5.7 ADO.NET UnknownStatement in fbScript.Parse()

我使用过 FirebirdClient 2.0 ADO.NET,我正在迁移到 FirebirdClint 5.7 版 ADO.NET。

下面的代码在新版本的 firebirdClient 中不起作用

If IO.File.Exists(pathScript) Then
        txtScript.Close()

        Dim fbScript As New FbScript(pathScript)

        fbScript.Parse()
        If fbScript.Results.Count = 0 Then
            Exit Sub
        End If

        If fbScript.Results.Count > 0 Then
            If automatico = False Then
                frmImpSintegra.LblTitulo.Text = "Gravando 60I"
            End If
            Application.DoEvents()

            Dim fbConn As New FbConnection(cnEmpresa)
            fbConn.Open()

            Dim fbBatch As New FirebirdSql.Data.Isql.FbBatchExecution(fbConn)
            fbBatch.AppendSqlStatements(fbScript)
            fbBatch.Execute(True)
            fbConn.Close()
        End If

        deleteArquivoTemporario()
        txtScript = New IO.StreamWriter(pathScript)
    End If

这个错误出现在行fbScript.Parse()

异常的完整堆栈跟踪:

Exception thrown: 'System.ArgumentException' in FirebirdSql.Data.FirebirdClient.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Exceção não tratada</Description><AppDomain>Livros.vshost.exe</AppDomain><Exception><ExceptionType>System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>The type of the SQL statement could not be determined. See also UnknownStatement event.
Statement: c:56_16122016_081323.txt.</Message><StackTrace>   em FirebirdSql.Data.Isql.FbScript.Parse()
   em Livros.importacaoSintegra.grava60I(Boolean automatico)
   em Livros.importacaoSintegra.importa60I(String linhaTexto, StreamWriter&amp;amp; txtScript, String diaEncerrado60, Boolean chkECF, Boolean automatico, String empresa, Boolean chkDiv60I, Boolean chkTruncar, String Impressoras, Boolean chkValida60I, Boolean chk60I75, Int32 contador)
   em Livros.importacaoSintegra.importaSintegraAutomatico(String txtPasta, Boolean automatico, String empresa, String txtMesAno, Boolean Chk74, String txtDataInventario, String txtTipoEstoque, Boolean ChkExcluirRegistro, Boolean chkAtualizarQuantidade, Boolean chkEcf, Boolean chkNf, Boolean ChkAtualizaCodigoInterno, Boolean chkVerCfop, String Cnpj_Empresa1, Boolean chkValida60I, Boolean chkAliquotaReal, Boolean chkDiv60I, Boolean chkTruncar, Boolean chk60I75, String mes1, String ano1, String cnAtual1, String cnEmpresa1, String CnPrincipalEmpresa1, Int32 idArquivoSpe1, Boolean chkSo75)
   em Livros.frmImpSintegra.btnConfirmarSinal_Click(Object sender, EventArgs e)
   em System.Windows.Forms.Control.OnClick(EventArgs e)
   em System.Windows.Forms.Button.OnClick(EventArgs e)
   em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   em System.Windows.Forms.Control.WmMouseUp(Message&amp;amp; m, MouseButtons button, Int32 clicks)
   em System.Windows.Forms.Control.WndProc(Message&amp;amp; m)
   em System.Windows.Forms.ButtonBase.WndProc(Message&amp;amp; m)
   em System.Windows.Forms.Button.WndProc(Message&amp;amp; m)
   em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp;amp; m)
   em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;amp; m)
   em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;amp; msg)
   em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   em Livros.My.MyApplication.Main(String[] Args)
   em System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   em System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   em System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   em System.Threading.ThreadHelper.ThreadStart()</StackTrace><ExceptionString>System.ArgumentException: The type of the SQL statement could not be determined. See also UnknownStatement event.
Statement: c:56_16122016_081323.txt.
   em FirebirdSql.Data.Isql.FbScript.Parse()
   em Livros.importacaoSintegra.grava60I(Boolean automatico)
   em Livros.importacaoSintegra.importa60I(String linhaTexto, StreamWriter&amp;amp; txtScript, String diaEncerrado60, Boolean chkECF, Boolean automatico, String empresa, Boolean chkDiv60I, Boolean chkTruncar, String Impressoras, Boolean chkValida60I, Boolean chk60I75, Int32 contador)
   em Livros.importacaoSintegra.importaSintegraAutomatico(String txtPasta, Boolean automatico, String empresa, String txtMesAno, Boolean Chk74, String txtDataInventario, String txtTipoEstoque, Boolean ChkExcluirRegistro, Boolean chkAtualizarQuantidade, Boolean chkEcf, Boolean chkNf, Boolean ChkAtualizaCodigoInterno, Boolean chkVerCfop, String Cnpj_Empresa1, Boolean chkValida60I, Boolean chkAliquotaReal, Boolean chkDiv60I, Boolean chkTruncar, Boolean chk60I75, String mes1, String ano1, String cnAtual1, String cnEmpresa1, String CnPrincipalEmpresa1, Int32 idArquivoSpe1, Boolean chkSo75)
   em Livros.frmImpSintegra.btnConfirmarSinal_Click(Object sender, EventArgs e)
   em System.Windows.Forms.Control.OnClick(EventArgs e)
   em System.Windows.Forms.Button.OnClick(EventArgs e)
   em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   em System.Windows.Forms.Control.WmMouseUp(Message&amp;amp; m, MouseButtons button, Int32 clicks)
   em System.Windows.Forms.Control.WndProc(Message&amp;amp; m)
   em System.Windows.Forms.ButtonBase.WndProc(Message&amp;amp; m)
   em System.Windows.Forms.Button.WndProc(Message&amp;amp; m)
   em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp;amp; m)
   em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;amp; m)
   em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;amp; msg)
   em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   em Livros.My.MyApplication.Main(String[] Args)
   em System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   em System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   em System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   em System.Threading.ThreadHelper.ThreadStart()</ExceptionString></Exception></TraceRecord>

我的 txt 文件是:

INSERT INTO REGISTRO_60I12 (TIPO,SUBTIPO,DATA_EMISSAO,NUMERO_SERIE,MODELO,COO,ITEM,PRODUTO_SERVICO,QUANTIDADE,VALOR_LIQUIDO,BASE_CALCULO,ALIQUOTA_SUBSTITUICAO,VALOR_ICMS,MESANO,EMPRESA)VALUES('60','I','2016.12.09','BE090910100010004937','2D',320645,'001','12036',1.000,3.99,0.00,'F',0.00,122016,0556);

有人可以帮助我吗?

您正在将文件名传递给 FbScript 的构造函数,但此构造函数需要实际的脚本内容。这导致文件名 c:56_16122016_081323.txt 被解析为一个语句,而 c:56_16122016_081323.txt 不是已知的 Firebird 语句。

您应该使用 FbScript.LoadFromFile(pathScript)