本文介绍了C#中的Ad Hoc查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的......我们走了......


我正在尝试从c#手动运行SQL服务器备份作业。这是我的代码开始这个过程的

片段:


string strSQL =" USE msdb" +

" \ n if exists(select * from sysjobs_view where name =''TempBackupJob'')" +

" \ n EXEC sp_delete_job @job_name =''TempBackupJob''" +

" \ n GO";

newDB.Command(strSQL);


此命令例外情况带有& ;'GO''附近的语法不正确。

现在,当我将EXACT相同的查询放入查询分析器时,这样:


USE msdb

如果存在(select * from sysjobs_view where name =''TempBackupJob'')

EXEC sp_delete_job @job_name =''TempBackupJob''

GO


命令执行没有任何错误。


换行字符有什么我想念的吗?我也尝试使用

\\ n而不是仅仅\ n来分隔线......这些也没用。


非常感谢任何帮助。

-

谢谢,


John Scott。

Ok...here we go...

I am trying to manually run an SQL server back up job from c#. Here is a
snippet of my code to begin the process:

string strSQL = "USE msdb " +
"\n if exists(select * from sysjobs_view where name = ''TempBackupJob'') " +
"\n EXEC sp_delete_job @job_name = ''TempBackupJob'' " +
"\n GO";
newDB.Command(strSQL);

This command exceptions with an "Incorrect syntax near ''GO''".
Now, when I put the EXACT same query into Query Analyzer like this:

USE msdb
if exists(select * from sysjobs_view where name = ''TempBackupJob'')
EXEC sp_delete_job @job_name = ''TempBackupJob''
GO

the command executes without any errors.

Is there something I''m missing with newline characters? I also tried using
\r\n instead of just \n to separate the lines...that didn''t work either.

Any help would be greatly appreciated.
--
Thanks,

John Scott.

推荐答案







这篇关于C#中的Ad Hoc查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 15:08