Click here to Skip to main content
15,897,704 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to Get LPDRAWITEMSTRUCT from CWnd pointer? Pin
RuiSantiago20-Nov-02 1:47
RuiSantiago20-Nov-02 1:47 
GeneralMyPen.CreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &logbr) fails in Win98 Pin
Daed19-Nov-02 22:31
Daed19-Nov-02 22:31 
GeneralRe: MyPen.CreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &logbr) fails in Win98 Pin
KarstenK20-Nov-02 1:23
mveKarstenK20-Nov-02 1:23 
GeneralDocking bars and statusbar problem Pin
BishGada19-Nov-02 22:17
BishGada19-Nov-02 22:17 
GeneralRe: Docking bars and statusbar problem Pin
KaЯl20-Nov-02 0:09
KaЯl20-Nov-02 0:09 
GeneralRe: Docking bars and statusbar problem Pin
BishGada20-Nov-02 1:52
BishGada20-Nov-02 1:52 
GeneralRe: Docking bars and statusbar problem Pin
KaЯl20-Nov-02 2:16
KaЯl20-Nov-02 2:16 
Generalhelp! perhaps u can spot this... Pin
devvvy19-Nov-02 22:12
devvvy19-Nov-02 22:12 
I keep getting an unknown runtime error 3705 or 0x0800A0E79 when I tried to open the recordset.

I tried look them up with VC's "Error Lookup". It says "Message Not Found"...


// ADOSchema.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#define INITGUID
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" rename_namespace("ADOCG") rename("EOF", "EndOfFile")
using namespace ADOCG;
#include "icrsint.h"


void DisplayHR(HRESULT hr, char * lpszErrorMsg)
{
int nCode = -1;

cout << endl;

cout << "ERROR MSG: " << lpszErrorMsg << endl;

nCode = SUCCEEDED(hr);
cout << "SUCCEEDED(hr) = " << nCode << endl;

nCode = HRESULT_SEVERITY(hr);
cout << "HRESULT_SEVERITY(hr) = " << nCode << endl;

nCode = HRESULT_CODE(hr);
cout << "HRESULT_CODE(hr) = " << nCode << endl;

return;
}


int main(int argc, char* argv[])
{
HRESULT hr;
char * pszErrorMsg = NULL;

char * pszTableName = NULL;
char ** pTableArray = NULL;
int nMaxTableNameLength = -1;
int nNumUserTable = -1;


::CoInitialize(NULL);

pszErrorMsg = new char[100];


//STEP 1: Connection object
_ConnectionPtr pConn = NULL;

hr = pConn.CreateInstance( __uuidof(Connection) );
if(hr!=S_OK)
{
//Additional error handling here.
:isplayHR(hr, "ERROR: failed to instantiate connection pointer");
return 1;
}

//Data Source=norm OR 127.0.0.1 (It doesnt matter, it's the default instance)
hr = pConn->Open(L"Provider=sqloledb; Data Source=127.0.0.1; Initial Catalog=realtime", L"sa", L"sa", NULL);
if(hr!=S_OK)
{
//Additional error handling here.
:isplayHR(hr, "ERROR: failed to establish connection with target database");
return 1;
}

//STEP 2: Command object.
_CommandPtr pCmd;
pCmd.CreateInstance( __uuidof(Command) );
pCmd->ActiveConnection = pConn;
pCmd->CommandText = "SELECT * FROM sysobjects";

//STEP 3: Recordset - play with it.
_RecordsetPtr pRs;

try
{
pRs = pCmd->Execute(NULL, NULL, adCmdText);
}
catch(_com_error &e)
{
//Additional error handling here.
cout << "ERROR: Failed to execute command." << endl;
cout << "ERROR msg: " << e.ErrorMessage() << endl;

hr = e.Error();
cout << "ERROR: HRESULT_CODE( e.Error() ): " << HRESULT_CODE(hr) << endl;

return 1;
}


//Null variant:
_variant_t vNull;
vNull.vt = VT_ERROR;
vNull.scode = DISP_E_PARAMNOTFOUND;

try
{
//CursorType: adOpenForwardOnly; LockType: adLockReadOnly; Option: adCmdUnknown
pRs->Open(vNull, vNull, adOpenForwardOnly, adLockReadOnly, adCmdUnknown);
}
catch(_com_error &e) //QUESTION: Runtime error HERE!!! Cant figure out why!!
{
//Additional error handling here.
cout << "ERROR: Failed to open recordset." << endl;
cout << "ERROR: e.ErrorMessage(): " << e.ErrorMessage() << endl; //CAUTION: This turns out to be "Unknown error 0x800A0E79.

hr = e.Error();
cout << "ERROR: HRESULT_CODE( e.Error() ): " << HRESULT_CODE(hr) << endl; //CAUTION: And this turns out to be 3705.

return 1;
}

//STEP 4: Retrieve a list of user tables from sysobjects
nMaxTableNameLength = 100;
pszTableName = new char [nMaxTableNameLength];


pRs->MoveFirst();
while( !EOF )
{
hr = pRs->MoveNext();
if( hr!=S_OK)
{
//Additional error handling here!
DisplayHR(hr, "ERROR: MoveNext");
}

//If field=xType==1, Then the object is a user table. Increment nNumUserTable here.

}



//STEP 4: Get individual table properties: Field/data type/number of records/number of columns/PK-FK.



//STEP 5: Cleanup
delete [] pszTableName;
delete [] pszErrorMsg;



CoUninitialize();

return 0;

}

Can anyone spot the error? i'm dying...



norm
GeneralRe: help! perhaps u can spot this... Pin
Shaun Wilde19-Nov-02 22:23
Shaun Wilde19-Nov-02 22:23 
GeneralRe: help! perhaps u can spot this... Pin
devvvy19-Nov-02 22:33
devvvy19-Nov-02 22:33 
GeneralRe: help! perhaps u can spot this... Pin
Shaun Wilde19-Nov-02 22:36
Shaun Wilde19-Nov-02 22:36 
GeneralRe: help! perhaps u can spot this... Pin
Shaun Wilde19-Nov-02 22:38
Shaun Wilde19-Nov-02 22:38 
GeneralRe: help! perhaps u can spot this... Pin
devvvy19-Nov-02 22:46
devvvy19-Nov-02 22:46 
GeneralRe: help! perhaps u can spot this... Pin
devvvy19-Nov-02 22:49
devvvy19-Nov-02 22:49 
GeneralRTF Formatting & preview Pin
Steve S19-Nov-02 22:06
Steve S19-Nov-02 22:06 
GeneralRe: RTF Formatting & preview Pin
Miguel Lopes20-Nov-02 4:51
Miguel Lopes20-Nov-02 4:51 
GeneralRe: RTF Formatting & preview Pin
Steve S20-Nov-02 5:04
Steve S20-Nov-02 5:04 
GeneralRe: RTF Formatting & preview Pin
Gary R. Wheeler20-Nov-02 14:02
Gary R. Wheeler20-Nov-02 14:02 
GeneralRe: RTF Formatting & preview Pin
Steve S20-Nov-02 21:52
Steve S20-Nov-02 21:52 
GeneralMaximize box Pin
suresh_sathya19-Nov-02 21:34
suresh_sathya19-Nov-02 21:34 
GeneralRe: Maximize box Pin
Paul M Watt19-Nov-02 22:15
mentorPaul M Watt19-Nov-02 22:15 
GeneralRe: Maximize box Pin
suresh_sathya19-Nov-02 22:22
suresh_sathya19-Nov-02 22:22 
GeneralWindow with multipe pages Pin
Luke Murray19-Nov-02 20:59
Luke Murray19-Nov-02 20:59 
GeneralRe: Window with multipe pages Pin
dima_t20-Nov-02 23:45
dima_t20-Nov-02 23:45 
Questioncan u use HRESULT_CODE in VC's tool "Error Lookup"? Pin
devvvy19-Nov-02 20:57
devvvy19-Nov-02 20:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.