RE: How do I use ADO in VC++ 7.0 to get the size of the database
- From: "MrSmersh" <MrSmersh@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 13 Jan 2006 07:08:03 -0800
I did found in my source code a code snippet doing something like this.
Most of the trick is to specify adCmdStoredProc as command parameter the
command will return a record set.
And using a store procedure to find database size I found that is the best
way.
Hope it answers your question.
CString sConString,sDBName;
try
{
_ConnectionPtr pConn("ADODB.Connection");
_CommandPtr pCmd("ADODB.Command");
_RecordsetPtr pRstDBs("ADODB.Recordset");
_variant_t vtEmpty (DISP_E_PARAMNOTFOUND, VT_ERROR);
_variant_t vtEmpty2(DISP_E_PARAMNOTFOUND, VT_ERROR);
//Real connection string
sConString=””;
_bstr_t bstrConString(sConString);
pConn->Open(bstrConString, "", "", adConnectUnspecified);
try
{
_bstr_t bstrCommand("sp_helpdb");
pCmd->ActiveConnection = pConn;
pCmd->CommandType = adCmdStoredProc;
pCmd->CommandText = bstrCommand;
pRstDBs = pCmd->Execute( &vtEmpty, &vtEmpty2,adCmdUnknown );
if(!pRstDBs->EndOfFile||!pRstDBs->BOF)
{
for(;!pRstDBs->EndOfFile;pRstDBs->MoveNext())
{
sDBName=(V_BSTR(&pRstDBs->Fields->GetItem( _variant_t( 0L ) )->Value));
}
}
pRstDBs->Close();
}
catch(_com_error &Err)
{
pConn->Close();
}
pConn->Close();
"Kjell Arne Johansen" wrote:
> How do I use ADO in VC++ 7.0 to get the size of the database.
> I know that sp_helpdb <database> returns size information.
> But how do I retrieve this information in my code?
>
> In my code I'm using _ConnectionPtr to execute commands,
> e.g. m_pConnection->Execute("EXEC procDoSomething", NULL, adExecuteNoRecords);
>
> Can I use m_pConnection to get the return value from a "sp_helpdb
> <database>" command?
>
> Are there other ways to retrieve the database size in Visual C++ using ADO?
>
> Regards
> Kjell Arne Johansen
>
.
- Prev by Date: Re: Command object stops prematurely w/o failure
- Next by Date: Can't instanciate Errors object in C++/MFC dialog app == :-(
- Previous by thread: Re: Command object stops prematurely w/o failure
- Next by thread: Can't instanciate Errors object in C++/MFC dialog app == :-(
- Index(es):
Relevant Pages
|