SQL Server xp_cmdshell

后端 未结 4 1457
慢半拍i
慢半拍i 2021-01-26 04:33

Is there any other way to get a list of file names via T-SQL other than

INSERT INTO @backups(filename)
EXEC master.sys.xp_cmdshell \'DIR /b c:\\som         


        
4条回答
  •  伪装坚强ぢ
    2021-01-26 04:43

    The alternative to xp_cmdshell I came up is below:

    My situation is a little unique in that I am attempting a poor man's log shipping. I have a folder (not the default SQL backup location) where transaction logs are deposited from a remote server. I am writing a c# app that loops through that directory and creates a comma delimited string of file names with paths (e.g. FooA.txn,FooB.txn,FooC.txn). I then feed this string into a stored procedure that I wrote which parses the string and inserts the file names into a temp table. Then I loop through the temp table restoring each transaction log in order.

    Basically the C# app replaces xp_cmdshell and from the app I can call a stored procedure.

提交回复
热议问题