English 中文(简体)
如何在 SQL 服务器 2008 中运行 SQL 工作 SQL 的 C# 控制台应用程序?
原标题:How to run C# Console application from SQL Job in SQL Server 2008?

我想尝试从 SQL 工作运行我的 C# 控制台应用程序。 因此, 为了测试它, 我简单地创建了一个控制台应用程序, 使用 C# 和 SMO, 写了几行来创建数据库 。 我可以成功运行它, 并按预期在 SQL 服务器上创建一个数据库 。

然后在 IDE 中,我点击了 build- & gt;Publish my project to E:myFolderMakeNewDB24 ,因为这就是我的 SQL 服务器所使用位置。

上述动作将下列文件复制到指定位置, 即 E: MyFolderMakeNewDB24

  • Application Files
  • setup.exe
  • myProject.application

Then I opened my SQL Server, created a job by rt. clicking Jobs Folder-->New Job. I filled all the information in General. In Steps, I have under Command,

\mySQLServermyFolderMakeNewDB24setup.exe

Type: Operating System(CmdExec)
Run as: SQL Server Agent Service Account

I ran the job. It showed the result as "Success" When I viewed the History,

Executed as user: mySQLServerSYSTEM. The step did not generate any output.  Process Exit Code 0.  The step succeeded.

我当时很开心。但是当我去查看应该创建的数据库时, 它并不存在, 意思是SQL JOB没有尽自己的职责来创建我的DB。

我不知道我错过了什么?如果有人知道这一点,请与我分享。我真的很想看到我的 SQL 工作做这个工作。我之所以使用SQL 工作是因为我所有的自动化任务都是从这里开始的。谢谢。

问题回答

您的问题几乎肯定与权限有关。 您需要检查用于运行 SQL 服务器代理任务的用户 ID 。 我猜它没有权限 。

您的工作返回成功的原因是 CMD 工作如果成功启动 CMD 可执行文件, 总是返回成功。 这与您的代码是否成功无关 。

在不需要我担心安全的环境中,我已经习惯于不幸地给予一切行政特权,所以我不必担心在哪里需要特权。祝你好运。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签