1
,我使用下面的腳本代碼,但它不工作..如何在sql server 2008中計算位於不同機器(遠程)上的文件夾大小?
DECLARE @TenantId UNIQUEIDENTIFIER ='A79ED820-2E5E-4A9D-B930-B7597DC97081'
DECLARE @BusinessName VARCHAR(200)
declare @line varchar(255) =''
declare @path varchar(255)=''
declare @command varchar(255)=''
DECLARE @folderSizeGB decimal (16,8) = 0
DECLARE @AttachmentDiscSpaceUsed decimal (16,8) = 0
- 代碼來計算文件夾大小GB開始
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
drop table #temp
create table #temp (line varchar(255))
set @path = '\\ewp-dev18\\c$\\Attachments\\' + CONVERT(varchar(50),@tenantId)
set @command = 'dir "' + @path +'"'
insert into #temp
exec master.dbo.xp_cmdshell @command
select @line=
ltrim(replace(substring(line, charindex(')', line)+1,
len(line)), ',', ''))
from #temp where line like '%File(s)%bytes'
SET @line=
(Case WHEN @line IS NULL or @line ='' THEN '0' ELSE @line END)
set @folderSizeGB = Cast(Replace(@line,'bytes', '') as decimal)/1073741824
if (@folderSizeGB is null)
set @folderSizeGB =0
SET @AttachmentDiscSpaceUsed = @folderSizeGB
SET @path=''
SET @command=''
SET @line=0
-- Drop #temp table
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
drop table #temp
- 代碼來計算GB端文件夾的大小
請幫助.. thanx提前
我試過這個,但它提出了「訪問被拒絕」的錯誤信息。但我可以訪問該遠程機器。我需要傳遞登錄憑證嗎?如果是,那麼將會是什麼腳本? – Rajesh