How can I get the return value from Sql Server system message?

后端 未结 2 1864
天涯浪人
天涯浪人 2020-12-19 13:27

I am trying to verify the backup I have just done in c# using command against sql server Express

 string _commandText =  string.Format(\"RESTORE VERIFYONLY F         


        
2条回答
  •  不知归路
    2020-12-19 14:22

    Its pretty difficult to retrieve the ssms message to the front end application . However you can write the message into a text file and then read the data from the file .

    declare @cmd varchar(1000)
    
    SET @cmd = 'osql -S YourServer -E -d YourDatabase -q "RESTORE VERIFYONLY FROM   DISK=''c:\yourBackup.bkp''" -o c:\result.txt'
    
    EXEC master.dbo.xp_cmdshell @cmd
    

    You can execute the above sql statements from your application and then read the result from the result.txt file

提交回复
热议问题