DBCC CheckDB

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
testiclesoup
Posts: 11
Joined: Mon 24 Dec 2012 04:46

DBCC CheckDB

Post by testiclesoup » Mon 24 Dec 2012 04:50

I am trying to find a way to execute a dbcc checkdb command from within my application. I want to parse the results looking for issue that need to be addressed. What component would be appropriate and how can I get access to the results as they do not return a result set?

Thanks,

Kevin

AndreyZ

Re: DBCC CheckDB

Post by AndreyZ » Mon 24 Dec 2012 10:37

Hello,

To execute the 'DBCC CHECKDB' statement, you should use the TMSQuery component. The results can be parsed in the TMSConnection.OnInfoMessage event handler. Here is a code example:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  MSQuery1.Connection := MSConnection1;
  MSQuery1.Execute;
end;

procedure TForm1.MSConnection1InfoMessage(Sender: TObject; E: EMSError);
begin
  Memo1.Lines.Add(E.Message);
end;
Note that to run this code, you should add the OLEDBAccess unit to the USES clause of your unit.

testiclesoup
Posts: 11
Joined: Mon 24 Dec 2012 04:46

Re: DBCC CheckDB

Post by testiclesoup » Mon 24 Dec 2012 15:55

Outstanding. It works very well.

Thanks for your help and thanks to the team for these are components.

AndreyZ

Re: DBCC CheckDB

Post by AndreyZ » Mon 24 Dec 2012 16:01

I am glad I could help. Feel free to contact us if you have any further questions about SDAC.

testiclesoup
Posts: 11
Joined: Mon 24 Dec 2012 04:46

Re: DBCC CheckDB

Post by testiclesoup » Thu 27 Dec 2012 22:56

I spoke a bit too soon. I got the first set of results just fine. But, when I try to run dbcc checkdb on a second database, the InfoMessage event doesn't fire. I have not yet been able to confirm that the second dbcc even happens. I have tried closing the query object before sending the new command to no avail. Is there something I need to do to make this work?

UnicodeString query("dbcc checkdb (");
query += pDatabases->Strings[0];
query += ")";

quMisc->Close();
quMisc->SQL->Clear();
quMisc->SQL->Add(query);
quMisc->Execute();

Thanks.

AndreyZ

Re: DBCC CheckDB

Post by AndreyZ » Fri 28 Dec 2012 09:42

I cannot reproduce the problem. I tried executing your code using SDAC 6.6.11 in C++Builder 2010, and there were no problems with its executing several times in a row for different databases. Please specify the following:
- the exact version of SDAC. You can learn it from the About sheet of TMSConnection Editor;
- the exact version of your IDE;
- the exact version of SQL Server server and client you are using. You can learn it from the Info sheet of TMSConnection Editor.

testiclesoup
Posts: 11
Joined: Mon 24 Dec 2012 04:46

Re: DBCC CheckDB

Post by testiclesoup » Fri 28 Dec 2012 14:59

SDAC version is 6.1.5.
Rad Studio XE2 version is 16.0.4429.46931.
Microsoft SQL Server: 09.00.4035
Microsoft SQL Native Client: 9.00.5000.00

AndreyZ

Re: DBCC CheckDB

Post by AndreyZ » Fri 28 Dec 2012 16:52

I still cannot reproduce the problem. Please try creating a small sample to demonstrate the problem and send it to andreyz*devart*com .
Also, you can try the following:
- unistall SDAC;
- update RAD Studio XE2 to version 16.0.4504.48759 (it is RAD Studio XE2 Update 4 with Hotfix 1);
- install SDAC 6.2.7 or higher.
After this, check if the problem persists in such environment.

testiclesoup
Posts: 11
Joined: Mon 24 Dec 2012 04:46

Re: DBCC CheckDB

Post by testiclesoup » Fri 28 Dec 2012 20:12

I figured it out. I went ahead and updated to the latest XE2 hotfix and to the most recent version of your components. That didn't help. It turns out that the issue was this: I was trying to run the next scan from inside of the InfoMessage event. I moved the execution of this event and it works just fine.

Thanks for your help.

Regards,

Kevin

Post Reply