1
我很抱歉如果我在這裏錯過了一些東西,我仍然在學習.NET。僅從VB.NET中的SQL Server過程中檢索PRINT命令
我有一個項目,我一直在努力恢復數據庫以及事務日誌。在每個事務日誌之後,我有一個PRINT語句來輸出事務日誌已被處理。
我一直在使用OnInfoMessage
功能得到了什麼是SQL Server中完成的消息,但一直在尋找出來的,只提取打印命令,並在文本框/標籤/ RichTextBox中作爲排序的顯示它狀態框會隨着更新而更新。
我在SQL Server程序如下
....
WHILE @@FETCH_STATUS=0
BEGIN
SET @sql = 'RESTORE LOG FCS FROM DISK = ''C:\Databases\'[email protected] +''' WITH NORECOVERY';
EXEC (@sql);
PRINT '===' [email protected];
FETCH NEXT FROM cFile INTO @fileName
END
CLOSE cFile
DEALLOCATE cFile
在VB.net我能夠得到的所有消息在日誌文件中顯示。
Private Shared Sub OnInfoMessage(ByVal sender As Object, ByVal e As System.Data.SqlClient.SqlInfoMessageEventArgs)
Using LogFile As IO.StreamWriter = New IO.StreamWriter("C:\SDBT\worklog.ft", True)
LogFile.WriteLine(e.Message)
End Using
End Sub
這反過來給了我下面的輸出...
Processed 10392 pages for database 'FCS', file 'FCS' on file 1.
Processed 2 pages for database 'FCS', file 'FCS_log' on file 1.
RESTORE DATABASE successfully processed 10394 pages in 2.652 seconds (30.619 MB/sec).
Processed 0 pages for database 'FCS', file 'FCS' on file 1.
Processed 6 pages for database 'FCS', file 'FCS_log' on file 1.
RESTORE LOG successfully processed 6 pages in 0.061 seconds (0.720 MB/sec).
===RESTORE LOG FCS FROM DISK = 'C:\SDBT_TestDB\log_00001.trn' WITH NORECOVERY
Processed 0 pages for database 'FCS', file 'FCS' on file 1.
Processed 2 pages for database 'FCS', file 'FCS_log' on file 1.
RESTORE LOG successfully processed 2 pages in 0.058 seconds (0.252 MB/sec).
===RESTORE LOG FCS FROM DISK = 'C:\SDBT_TestDB\log_00002.trn' WITH NORECOVERY
理想情況下,我想只檢索前面有「===」和輸出那些給用戶線。
是否有可能從SQL Server獲得@sql
變量值到VB.net,或者是否有內置.NET的東西,我失蹤了?
在此先感謝!
這個工程很漂亮!現在讓它在文本框中顯示出來,因爲它一步一步地完成,我很好!謝謝! – ephtee
很高興能有幫助!如果您覺得這對您有用,請隨時[接受我的回答](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answe r-work)。 – Stone