Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xp\u CmdShell,仅将映像写入SQL Server所在的位置。而不是写入我想要的服务器(位置)_Sql_Sql Server_Sql Server 2008 - Fatal编程技术网

xp\u CmdShell,仅将映像写入SQL Server所在的位置。而不是写入我想要的服务器(位置)

xp\u CmdShell,仅将映像写入SQL Server所在的位置。而不是写入我想要的服务器(位置),sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,我在sp中使用xp_CmdShell将图像写入C:\ImageUpload这样的位置。这在承载SQL server的服务器位置上工作得非常好。我知道这可能是典型的行为 然而,我的一个客户机拥有自己的服务器,其中承载着数据库。他需要将映像写入另一个服务器位置 SET @strOutputFilePath = C:/ImageUpload -- Get Final Path SET @strOutputFilePath = @strOutputFilePath + @strFilename P

我在sp中使用xp_CmdShell将图像写入C:\ImageUpload这样的位置。这在承载SQL server的服务器位置上工作得非常好。我知道这可能是典型的行为

然而,我的一个客户机拥有自己的服务器,其中承载着数据库。他需要将映像写入另一个服务器位置

SET @strOutputFilePath = C:/ImageUpload

-- Get Final Path
SET   @strOutputFilePath = @strOutputFilePath + @strFilename
PRINT @strOutputFilePath -- path will be like C:\ImageUpload\NameofFile
SET   @strSql = 'BCP "set fmtonly off SELECT BlobImage FROM dbo.TblImage where ID = ' + CAST(@id AS VARCHAR(10)) +''
                    + '" QUERYOUT ' + '"' +@strOutputFilePath+ '"' + ' -T -f C:\Test\testblob.fmt -S"' + @@SERVERNAME + '"'
PRINT @strSql  
EXEC  @RC = master.dbo.xp_CmdShell @strSql
PRINT @RC
下面是我的SQL sp的一部分。它通常工作正常,但在上面的情况下,我想将映像写入另一个服务器位置

SET @strOutputFilePath = C:/ImageUpload

-- Get Final Path
SET   @strOutputFilePath = @strOutputFilePath + @strFilename
PRINT @strOutputFilePath -- path will be like C:\ImageUpload\NameofFile
SET   @strSql = 'BCP "set fmtonly off SELECT BlobImage FROM dbo.TblImage where ID = ' + CAST(@id AS VARCHAR(10)) +''
                    + '" QUERYOUT ' + '"' +@strOutputFilePath+ '"' + ' -T -f C:\Test\testblob.fmt -S"' + @@SERVERNAME + '"'
PRINT @strSql  
EXEC  @RC = master.dbo.xp_CmdShell @strSql
PRINT @RC

如何指定特定的服务器位置,以便将映像写入该文件夹而不是SQL server所在的文件夹?

您需要做一些事情

  • 更新服务器以使用UNC路径。因此,对位置的引用 应读取\\ServerName\FileShare\File.txt而不是 驱动器:\Directory\File.txt

  • 如果SQL server安装正确且安全,则帐户 xp\u cmdshell使用的可能没有权限。所以要么允许 服务帐户对共享文件夹的权限或(更多) 安全方法)为xp\u cmdshell设置代理帐户。通过让xp_cmdshell发出命令
    whoami


  • ##当我使用。。。它使用安装数据库的服务器位置,如Server1 C folder,但我想要Server2 C folder…。在示例中,\\ServerName应该是目标服务器。如果不设置网络共享,也可以使用管理员共享。因此,如果您的SQL Server是SRV1,但您的文件共享是SRV2,那么您将使用\\SRV2\c$\Folder\。。。