How do I use ADO in VC++ 7.0 to get the size of the database  
Author Message
j-in-uk





PostPosted: Thu Jan 12 07:57:44 CST 2006 Top

SQL Server Developer >> How do I use ADO in VC++ 7.0 to get the size of the database

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

SQL Server45  
 
 
JT





PostPosted: Thu Jan 12 07:57:44 CST 2006 Top

SQL Server Developer >> How do I use ADO in VC++ 7.0 to get the size of the database Try microsoft.public.data.ado



> 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


 
 
Craig





PostPosted: Fri Jan 13 13:33:44 CST 2006 Top

SQL Server Developer >> How do I use ADO in VC++ 7.0 to get the size of the database

> 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


 
 
KjellArneJohansen





PostPosted: Tue Jan 17 01:00:03 CST 2006 Top

SQL Server Developer >> How do I use ADO in VC++ 7.0 to get the size of the database Thank You!

Kjell Arne



> 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
 
 
KjellArneJohansen





PostPosted: Tue Jan 17 01:01:02 CST 2006 Top

SQL Server Developer >> How do I use ADO in VC++ 7.0 to get the size of the database Thank You!

Kjell Arne




>
> > 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
>
>
>