无法在SQL Server 2008 R2作业中打开脚本文件

时间:2011-08-19 20:30:07

标签: sql-server-2008

当我尝试从SQL Server作业配置窗口打开本地计算机上的SQL脚本文件时,出现以下错误:

  

拒绝访问路径'C:\ temp \ tbl_MiscInfo.sql'。 (mscorlib程序)

     

计划地点:

     

at System.IO .__ Error.WinIOError(Int32 errorCode,String   maybeFullPath)at System.IO.FileStream.Init(String path,FileMode   模式,FileAccess访问,Int32权限,布尔useRights,FileShare   share,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES   secAttrs,String msgPath,Boolean bFromProxy)at   System.IO.FileStream..ctor(String path,FileMode mode,FileAccess   访问,FileShare共享)在System.IO.File.Open(String path,   FileMode模式)at   Microsoft.SqlServer.Management.SqlManagerUI.TSQLJobSubSystemDefinition.openFile_Click(对象   发件人,EventArgs e)at   System.Windows.Forms.Control.OnClick(EventArgs e)at   System.Windows.Forms.Button.OnClick(EventArgs e)at   System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)at at   System.Windows.Forms.Control.WmMouseUp(Message& m,MouseButtons   按钮,Int32点击)at   System.Windows.Forms.Control.WndProc(Message& m)at   System.Windows.Forms.ButtonBase.WndProc(Message& m)at   System.Windows.Forms.Button.WndProc(Message& m)at   System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)   在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&   m)在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32)   msg,IntPtr wparam,IntPtr lparam)

要清楚,这是我正在尝试执行的操作的屏幕截图:

enter image description here

这似乎是一个权限问题,但我尝试的任何内容似乎都无效。

我机器上的sqlagent正在使用具有管理员权限的用户,我已为该作业登录了具有管理员权限的用户凭据,并且我已将“运行为用户”选项设置为用户映射使用管理员权限登录。

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

它不起作用。当您单击“打开...”时,它所做的只是获取您指定的文件的内容并将其转储到Command:对话框中 - 这意味着该脚本是静态的,不会反映您在保存作业后所做的任何更改。

如果您希望它在运行时使用.sql文件,您需要查看使用CmdExec步骤类型(您可以在SQL Server进程外调用SQLCmd)或PowerShell命令。或者,作业步骤可以使用xp_cmdshell读取.sql脚本的内容(使用type命令)并将内容作为动态SQL执行。