需要通过C#执行spool命令吗? [英] Need to execute spool command through C #?

查看:88
本文介绍了需要通过C#执行spool命令吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将异常视为无效的sql语句!!!



我尝试过的方法:



spool myfile.txt ;

我的查询结果集;

假脱机;

Giving Exception as Invalid sql Statement!!!

What I have tried:

spool myfile.txt ;
my query result set;
spool off;

推荐答案

评论中的代码是VB.Net而不是C#。



[Payroll.Payslip ] .Payslip看起来不像是有效的表名。



您正在尝试执行包含多个命令的脚本。这不会这样。您必须自己发送每个命令,或将命令放入 BEGIN - END 块。



我不确定但这可行:

The code from your comment is VB.Net and not C#.

"[Payroll.Payslip].Payslip" does not look like a valid table name.

You are trying to execute a script containing multiple commands. This won't work this way. You have to either send each command on it's own, or put the commands into a BEGIN - END block.

I'm not sure but this might work:
.AppendLine("BEGIN")
.AppendLine("spool D:\30Aug\Testing.txt")
.AppendLine("SELECT * FROM [Payroll.Payslip].Payslip WHERE PayslipID > 1500")
.AppendLine("spool off")
.AppendLine("END;")

请注意,除了最后一个命令之后没有分号。



您还应该捕获异常以获取数据库引擎的错误消息:

Note that there are no semicolons besides that after the last command.

You should also catch exceptions to get the error message of the database engine:

Try
    ' Code goes here
Catch e As OracleException
    Dim errorMessage As String = "Code: " & e.Code & vbCrLf & "Message: " & e.Message
    ' Report error here
End Try

这些有助于识别SQL语法错误。





SPOOL 是Oracle SQL * Plus 命令。这是一个Oracle数据库命令行实用程序。所以这个命令不能和通用的编程语言接口一起使用。



甚至不需要这样的输出,因为接口提供了所有的数据写入文件。只需像往常一样执行查询并迭代结果集。如果需要文件输出,请在迭代循环中执行此操作。

[/ EDIT]

These help to identify SQL syntax errors.


SPOOL is an Oracle SQL*Plus command. That is an Oracle database command line utility. So this command can't be used with the common programming language interfaces.

There is even no need for such an output because the interface provides all the data which would be written to the file. Just execute the query as usual and iterate over the result set. If file output is required, do that in the iteration loop.
[/EDIT]


这篇关于需要通过C#执行spool命令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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