Home All Groups Group Topic Archive Search About

How do I use ADO in VC++ 7.0 to get the size of the database

Author
12 Jan 2006 12:43 PM
Kjell Arne Johansen
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

Author
12 Jan 2006 1:57 PM
JT
Try microsoft.public.data.ado

Show quote
"Kjell Arne Johansen" <KjellArneJohan***@discussions.microsoft.com> wrote in
message news:72BCAD75-24AB-40E9-9228-2501B48D005F@microsoft.com...
> 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
Author
13 Jan 2006 7:33 PM
Craig Kelly
Show quote
"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

You would use _RecordsetPtr to read the returned results...

_RecordsetPtr r = m_pConnection->Execute("exec sp_helpdb 'master'", NULL,
0);

.... Then you would read the appropriate data...

cout << var2stl(r->Fields->Item["db_size"]->Value);

....I use two helper functions for translating _variant_t's and _bstr_t's to
std:string's for display purposes (which I was using above).  I point these
out because of two gotcha's with COM, #import, and the helper types: an
empty BSTR is equivalent to a NULL BSTR and VARIANT's can be NULL...

inline string bstr2stl(const _bstr_t& b)
{
    const char* c = b.operator const char *();
    return c ? c : "";
}

inline string var2stl(const _variant_t& v)
{
    if (VT_NULL == v.vt)
        return "{NULL}";

    return bstr2stl(v.operator _bstr_t());
}


Craig
Author
17 Jan 2006 7:01 AM
Kjell Arne Johansen
Thank You!

Kjell Arne

Show quote
"Craig Kelly" wrote:

> "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
>
> You would use _RecordsetPtr to read the returned results...
>
> _RecordsetPtr r = m_pConnection->Execute("exec sp_helpdb 'master'", NULL,
> 0);
>
> .... Then you would read the appropriate data...
>
> cout << var2stl(r->Fields->Item["db_size"]->Value);
>
> ....I use two helper functions for translating _variant_t's and _bstr_t's to
> std:string's for display purposes (which I was using above).  I point these
> out because of two gotcha's with COM, #import, and the helper types: an
> empty BSTR is equivalent to a NULL BSTR and VARIANT's can be NULL...
>
> inline string bstr2stl(const _bstr_t& b)
> {
>     const char* c = b.operator const char *();
>     return c ? c : "";
> }
>
> inline string var2stl(const _variant_t& v)
> {
>     if (VT_NULL == v.vt)
>         return "{NULL}";
>
>     return bstr2stl(v.operator _bstr_t());
> }
>
>
> Craig
>
>
>
Author
17 Jan 2006 7:00 AM
Kjell Arne Johansen
Thank You!

Kjell Arne

Show quote
"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

AddThis Social Bookmark Button