Article View: borland.public.cppbuilder.database.ado
Article #4814How Do I Trap where the open fails
From: Dale
Date: Tue, 02 Oct 2001 23:11
Date: Tue, 02 Oct 2001 23:11
72 lines
2716 bytes
2716 bytes
How do I trap the erro when the open fails. Currently I have a cheeze ball
msg. How do I get better error trapping?
How do I tell the query is bad and not the connection string other than the
obvious make a separate connection object.
#include <initguid.h> // Include only once in your application
#include "adoid.h" // ADO GUID's
#include "adoint.h" // ADO Classes, enums, etc.
#include "stdio.h"
#pragma argsused
int main(int argc, char* argv[])
{
CoInitialize(NULL);
HRESULT hr = S_OK;
ADORecordset* Rs1 = NULL;
VARIANT Source;
VARIANT Connect;
VariantInit( &Source );
VariantInit( &Connect );
Source.vt = VT_BSTR;
Source.bstrVal = ::SysAllocString( L"SELECT * FROM shiftclass1"); //
the query is wrong
Connect.vt = VT_BSTR;
Connect.bstrVal = ::SysAllocString( L"Provider=SQLOLEDB.1;Persist
Security Info=False;User ID=sa;Initial Catalog=dale_test;Data
Source=DEV3-WSMITH" );
hr = CoCreateInstance( CLSID_CADORecordset,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADORecordset,
(LPVOID *) &Rs1 );
if( SUCCEEDED( hr ) ) hr = Rs1->Open( Source,
Connect,
adOpenForwardOnly,
adLockReadOnly,
-1 );
}
if( SUCCEEDED( hr ) )
{
hr = Rs1->Close();
}
else
}
printf("the query has failed"); // pure cheeze
}
if( SUCCEEDED( hr ) ) { Rs1->Release(); Rs1 = NULL; }
if( SUCCEEDED( hr ) ) ::MessageBox( NULL, "Success!", "", MB_OK );
CoUninitialize();
}
thanks
dale
Technical Details
Message-ID:
<3bba49a6$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!hammer.uoregon.edu!canoe.uoregon.edu!arclight.uoregon.edu!logbridge.uoregon.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,51f69349acb4ad8d,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2001-10-02 16:12:15 PST From: "Dale" <Dkrebbers@cenadex.com> Newsgroups: borland.public.cppbuilder.database.ado Subject: How Do I Trap where the open fails Date: Tue, 2 Oct 2001 16:11:19 -0700 Lines: 74 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 24.67.186.198 Message-ID: <3bba49a6$1_1@dnews> X-Trace: dnews 1002064294 24.67.186.198 (2 Oct 2001 16:11:34 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!hammer.uoregon.edu!canoe.uoregon.edu!arclight.uoregon.edu!logbridge.uoregon.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews