xp\u CmdShell,仅将映像写入SQL Server所在的位置。而不是写入我想要的服务器(位置)
我在sp中使用xp_CmdShell将图像写入C:\ImageUpload这样的位置。这在承载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
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所在的文件夹?您需要做一些事情
whoami
##当我使用。。。它使用安装数据库的服务器位置,如Server1 C folder,但我想要Server2 C folder…。在示例中,\\ServerName应该是目标服务器。如果不设置网络共享,也可以使用管理员共享。因此,如果您的SQL Server是SRV1,但您的文件共享是SRV2,那么您将使用\\SRV2\c$\Folder\。。。