DBCC CheckDb - 任何检测错误的方法 vb.net?
DBCC CheckDb-any ways to detect errors vb.net?
我正在使用以下代码检查我的数据库是否有任何 issues/requires 故障排除:
Dim cmd As New SqlCommand("DBCC CHECKDB (offpoDb) WITH TABLERESULTS", con)
Dim reader As SqlDataReader = cmd.ExecuteReader
executing.Content = "Checking datatabse for errors"
executing.Margin = New Thickness(243, 111, 0, 0)
While reader.Read
strBuilder.AppendLine(CStr(reader("MessageText")))
End While
reader.Close()
MessageBox.Show(strBuilder.ToString)
现在,DBCC CHECKDB
命令可能会产生如下结果:
CHECKDB found 0 allocation errors and 15 consistency errors in database 'mydb
可以修复以下 SQL 查询:
ALTER DATABASE AdventureWorks2008R2 SET SINGLE_USER WITH ROLLBACK
IMMEDIATE;
BEGIN TRANSACTION;
DBCC CHECKDB ('AdventureWorks2008R2', REPAIR_ALLOW_DATA_LOSS);
ALTER DATABASE AdventureWorks2008R2 SET MULTI_USER;
但是在通过我的应用程序执行以下查询之前,有没有办法知道 DBCC CHECKDB
是否真的返回了任何错误?因为没有任何错误,修复数据库就没有用了...
有什么帮助吗?
我的一个想法
我正在考虑从 strBuilder
获取字符串到 textbox.The 文本框将检查以下行的可用性 CHECKDB found 0 allocation errors and 15 consistency errors in database
..
但这仍然是不可能的,因为那条线有时可能与 time.E.g.
不同
CHECKDB found 0 allocation errors and 15 consistency errors
CHECKDB found 1 allocation errors and 14 consistency errors
有更好的主意吗?
有多种可能性:
1.
在命令中添加NO_INFOMSGS
选项。
这样,如果没有发现错误,则不会返回任何记录。
DBCC CHECKDB (dname) WITH TABLERESULTS, NO_INFOMSGS
2.
读取第 Level
列的值。如果一个大于 10
,则发生错误。 (Reference)
您可能遇到的 DBCC 错误列表:
SELECT * FROM sys.sysmessages
WHERE description LIKE '%checkdb%' AND msglangid = 1033 AND severity > 10
3.
检查结果字符串中是否有大于 0
的数字。
For Each c As Char In "CHECKDB found 0 allocation errors and 15 consistency errors"
If (Char.IsNumber(c)) AndAlso Integer.Parse(c) > 0 Then
'Errors occured
End If
Next
我正在使用以下代码检查我的数据库是否有任何 issues/requires 故障排除:
Dim cmd As New SqlCommand("DBCC CHECKDB (offpoDb) WITH TABLERESULTS", con)
Dim reader As SqlDataReader = cmd.ExecuteReader
executing.Content = "Checking datatabse for errors"
executing.Margin = New Thickness(243, 111, 0, 0)
While reader.Read
strBuilder.AppendLine(CStr(reader("MessageText")))
End While
reader.Close()
MessageBox.Show(strBuilder.ToString)
现在,DBCC CHECKDB
命令可能会产生如下结果:
CHECKDB found 0 allocation errors and 15 consistency errors in database 'mydb
可以修复以下 SQL 查询:
ALTER DATABASE AdventureWorks2008R2 SET SINGLE_USER WITH ROLLBACK
IMMEDIATE;
BEGIN TRANSACTION;
DBCC CHECKDB ('AdventureWorks2008R2', REPAIR_ALLOW_DATA_LOSS);
ALTER DATABASE AdventureWorks2008R2 SET MULTI_USER;
但是在通过我的应用程序执行以下查询之前,有没有办法知道 DBCC CHECKDB
是否真的返回了任何错误?因为没有任何错误,修复数据库就没有用了...
有什么帮助吗?
我的一个想法
我正在考虑从 strBuilder
获取字符串到 textbox.The 文本框将检查以下行的可用性 CHECKDB found 0 allocation errors and 15 consistency errors in database
..
但这仍然是不可能的,因为那条线有时可能与 time.E.g.
不同CHECKDB found 0 allocation errors and 15 consistency errors
CHECKDB found 1 allocation errors and 14 consistency errors
有更好的主意吗?
有多种可能性:
1.
在命令中添加NO_INFOMSGS
选项。
这样,如果没有发现错误,则不会返回任何记录。
DBCC CHECKDB (dname) WITH TABLERESULTS, NO_INFOMSGS
2.
读取第 Level
列的值。如果一个大于 10
,则发生错误。 (Reference)
您可能遇到的 DBCC 错误列表:
SELECT * FROM sys.sysmessages
WHERE description LIKE '%checkdb%' AND msglangid = 1033 AND severity > 10
3.
检查结果字符串中是否有大于 0
的数字。
For Each c As Char In "CHECKDB found 0 allocation errors and 15 consistency errors"
If (Char.IsNumber(c)) AndAlso Integer.Parse(c) > 0 Then
'Errors occured
End If
Next