ADO Exceptions

������: "Tony Tanm" <tony21st@sina.com.cn>
����: One question about ADO
����: 2003��8��22�� 14:48

I use ADO in my application to access database,when I give the parameter
ConnectionString of connection's method Open a wrong value(say,data source
that doesn't exist),my program will arouse exception, through step
debugging, I found that the following code [in msado20.tli file]
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
lead to the exception. I'm puzzled about it. Somebody help me please. Thanks
in advance.






0
tony21st (7)
8/22/2003 9:51:00 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
1055 Views

Similar Articles

[PageSpeed] 46

Tony,

you have several options...

1.  you can call the raw ADO methods -and handle the error codes in your
app

2.  use the #import wrapper classes, and handle the com_error exception

Here are a couple of examples:

This one uses the wrapper classes exception handler:
/* *************************************************** */
_ConnectionPtr OraConnect;
OraConnect.CreateInstance(__uuidof(Connection));
_RecordsetPtr OraRset;
OraRset.CreateInstance(__uuidof(Recordset));

try{
 _bstr_t oraProvider(L"Provider=ORAOLEDB.Oracle;Data Source=xxx;");
 OraConnect->Open(oraProvider,L"SAMTM",L"SAMTM",adConnectUnspecified);
 OraRset->PutRefActiveConnection(OraConnect);
 OraRset->Open(L"Select count(*) from Import_Holding where
state='UT'",vtMissing,adOpenForwardOnly,adLockReadOnly,adCmdText);
 long rcval = OraRset->GetCollect((short)0).lVal;
 }
catch(_com_error &e){
// do something here to handle the error
 }


This one uses the raw methods:
/* *************************************************** */
_ConnectionPtr OraConnect;
OraConnect.CreateInstance(__uuidof(Connection));
_RecordsetPtr OraRset;
OraRset.CreateInstance(__uuidof(Recordset));

try{
 _bstr_t oraProvider(L"Provider=ORAOLEDB.Oracle;Data Source=xxx;");
 HRESULT hr =
OraConnect->raw_Open(oraProvider,_bstr_t(L"SAMTM"),_bstr_t(L"SAMTM"),adC
onnectUnspecified);
 if(FAILED(hr)){
  // do something here to handle the error
  }
 }


i hope this helps..

regards
roy fine

"Tony Tanm" <tony21st@sina.com.cn> wrote in message
news:#im5fKJaDHA.2932@tk2msftngp13.phx.gbl...
>
> ������: "Tony Tanm" <tony21st@sina.com.cn>
> ����: One question about ADO
> ����: 2003��8��22�� 14:48
>
> I use ADO in my application to access database,when I give the
parameter
> ConnectionString of connection's method Open a wrong value(say,data
source
> that doesn't exist),my program will arouse exception, through step
> debugging, I found that the following code [in msado20.tli file]
>     if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
> lead to the exception. I'm puzzled about it. Somebody help me please.
Thanks
> in advance.
>
>
>
>
>
>


0
rlfine5330 (47)
8/22/2003 2:49:13 PM
Reply:

Similar Artilces:

ADO connect mysql
Dear Sirs, I want to use mysql as database,and work on the datas through ADO in the excel. so I get exchange the datas with Excel and mysql. This is best way for my works I can imagine this moment. Please help me to provide me code how to establish connection from Excel to mysql. thanks advancely. Best regards http://forums.mysql.com/read.php?10,100302 Tim "Li Jianyong" <LiJianyong@discussions.microsoft.com> wrote in message news:56BC5ABE-CBB6-4F76-B956-32153ECDB5AD@microsoft.com... > Dear Sirs, > > I want to use mysql as database,and wo...

Exception Lists
Trying to configure my exception list so that it does not filter any internal email. So far the only way I can get it to work is by putting the "Alias" in the exception list with over 600 users this solution would be impossible. Is there a way to add the local domain to my exception list? Have also tried using "server name.domain.com" Thank in advance -craig ...

ADO
Hi, Can I use ActiveX Data Objects(ADO) with any ODBC compliant database to access data? Hi Rishi; Yes you can do that easily, by choosing ODBC connection in the Ado Control properties... Monther "Rishi Shah" <rishi.shah@patni.com> wrote in message news:758be1e.0307232203.1478afee@posting.google.com... > Hi, > > Can I use ActiveX Data Objects(ADO) with any ODBC compliant database to access data? ...

Timerproc exception
I have a UI thread whose only function is to start a timer which uses a timerproc callback void CALLBACK timerproc (HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) Trying to trace a random deadlock bug I found that on occasion the callback would cause an exception in the C library function fgets (called with a NULL file pointer). What surprised me is that the exception (which neither CException nor std::exception seems to catch) just has the effect of silently exiting from the timerproc. The timer fires again and the application continues. Is this behaviour normal? I would have exp...

what is the ODBC and ADO??
hi I want to know what is the difference between ODBC and ADO??? thank you bye These may be of interest... http://msdn2.microsoft.com/en-us/library/aa906098.aspx http://msdn2.microsoft.com/en-us/library/ms810810.aspx Mark -- Mark Salsbery Microsoft MVP - Visual C++ "mohaz" <mohaz14@yahoo.com> wrote in message news:1187482742.311579.259080@w3g2000hsg.googlegroups.com... > hi > I want to know what is the difference between ODBC and ADO??? > thank you > bye > "mohaz" <mohaz14@yahoo.com> wrote in message news:1187482742.311579.259080@w3g...

ADO Not Opening Recordset
Help: I am just starting at a new company, and am having issues getting Access to perform ADO.recordset operations correctly. And, there is no "go-to" person here. I am just trying to use automation to make my life easier. The code below returns an empty recordset ("-1" on the message box which I added as a test). It finishes with an error message I assume that I am just missing a library. I do have the MS ADO 2.8 and VBA libraries selected in references. My version is Access 2003. Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset With rs .Act...

Should I Learn DAO, ADO or ADO.NET ?
Hello Microsoft MVPs, learned programmers, and other VBA newbies, I am teaching myself VBA using Access 2007 Visual Basic Editor. I am confused about which tools I should be learning to access the records in my database. I have read that DAO is native and fastest, but also that DAO is obsolete and anything new should be written using ADO.Net Is ADO.Net supported under Access 2007 VBA Editor? What about Access 2003? Does each set of tools have certain situations where it is best suited? If so, what are those situations? Should I learn: 1) DAO 2) ADO 3) ADO.Net Thank you for being ...

Exception thrown inside AfxWndProc
I've had a dump file that have the following call stack. mfc42u!AfxCallWndProc+0x8b mfc42u!AfxWndProc+0x36 CapPRG!AfxWndProcDllStatic+0x2e .... .... CapPRG!CapPRGStatic::showUp+0x25 CapPRG!CapPRGMainDlg::OnInitDialog+0x7fa Basic what is happening is that inside CapPRGStatic::showUp(), function CWnd::MoveWindow() is called, which generats a window message WM_WINDOWMOVING which is send to AfxWndProcDllStatic for processing. The direct cause of the exception is inside function (MFC4.2) AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam) { // special message which identifies the...

Code to Print Entire Workbook Except for One Sheet
I wanted to know what would be the VBA Code I could put behind a butto to Print All Worksheets in a workbook EXCEPT for the sheet name MainForm? Thank -- Message posted from http://www.ExcelForum.com Hi try something like sub print_it dim wks as worksheet for each wks in activeworkbook.worksheets if lcase(wks.name)<>"your_sheet" then wks.printout end if next end sub -- Regards Frank Kabel Frankfurt, Germany > I wanted to know what would be the VBA Code I could put behind a > button to Print All Worksheets in a workbook EXCEPT for the sheet > name...

Junk eMail rule- way to use Contacts as Exceptions?
Is there a way to use everyone in Contacts as the Exception list- without having to add them one by one to the Exception list? Clearly- anyone in our Contacts would not be Junk senders- and not having to add people to the exception list would be cool... Thanks in advance! Yes you can. "John Noble" <bizzdevsans@spampacbell.net> wrote in message news:MfXOa.491$4H2.40321174@newssvr21.news.prodigy.com... > Is there a way to use everyone in Contacts as the Exception list- without > having to add them one by one to the Exception list? Clearly- anyone in our > Contact...

ADO
Hello, I use this instruction in excel but I have an error do you know why ? Dim Cnx As New ADODB.Connection No Dave wrote: > Hello, > > I use this instruction in excel but I have an error > do you know why ? > > Dim Cnx As New ADODB.Connection Now that answer wasn't useful, I know. Now, describe the error that you are getting? Dave wrote: > Hello, > > I use this instruction in excel but I have an error > do you know why ? > > Dim Cnx As New ADODB.Connection > I use this instruction in excel but I have an error > do you know why ? &...

linked table from excel via vba and ADO object
Hi all,is there a way to automate linked table with the ADO object using VBAof course...

ADO or DAO?
I have two Access 2000 texts. One uses ADO (and says DAO is outmoded technology - is this true?) and the other uses DAO. I must say, the DAO commands seem less complicated, at least when it comes to opening a recordset. If your data is stored in Access tables, use DAO. DAO is the native Access library. The A in DAO *is* Access. Access itself uses it (e.g. to run its queries.) When Access 2000 was released, MS did try to get us to switch to the more generic ADO. That's where the "outmoded" comments originated. Since that time, ADO has become outmoded as a generic librar...

turn Calculation OFF from columnB to BT except column A
Hi the experts, I have a data worksheet ranging from column A to BT and covering 6880 rows. I have maintained a few columns in between with Sumproduct and If(Countif()) formulas. Whenever I insert columns and vlookup values to other worksheets, the calculation takes very long. I only want to leave Calculation ON for Cell A1 and turn Calculation manually OFF for the rest of the formulas in between column B to column BT. How am I be able to do that with VBA code ?? Formula in Cell A1 is the items-counter only. A1=SUBTOTAL(9,C2:C6880) I would be very very grateful if someone can help m...

vc++ 2005 unhandled exception error: settings
vc++ 2005 unhandled exception error: settings ? Unhandled exception at 0x0040c247 in jan7.exe: 0xC0000005: Access violation reading location 0x00030000. This is too less information. Seems to be a pointer access problem. Have you debugged the code? Then you can find the error. <farshid.roumi@gmail.com> schrieb im Newsbeitrag news:1168247063.905620.57180@38g2000cwa.googlegroups.com... > vc++ 2005 unhandled exception error: settings ? > > > Unhandled exception at 0x0040c247 in jan7.exe: 0xC0000005: Access > violation reading location 0x00030000. > Looks like a ...

ADO And Sockets
Hi All I have written a server application, which accepts info from other client machine (this for the present is being simulated wthrough HyperTerminal). After I reviece a packet from the Hyper terminal (comprising of a UserID and Passwd), I check against a DB (I am Using ADO DB Calls). I am trying to open the DB connection and the Recordeset inside the Server thread. Here it fails, (Open returns a FALSE). The DB Calls works well outside the thread Can the DB Calls be never made from within a thread.. Please advise. Any Help is appreciated TheBasilisk ADO works well in multithreaded...

Worksheet protection with exceptions
I have been using the following code to protect all worksheets in a workbook: Public Sub ProtectAll() Const PWORD As String = "mysecretword" Dim wsSheet As Worksheet For Each wsSheet In Worksheets wsSheet.Protect Password:=PWORD Next wsSheet End Sub This password protects all sheets without exceptions. Is there any way to modify the code so that it protects all sheets but it universally allows editing of objects, autofilter, and Pivot reports? If you're using Excel 2002, or later version: Public Sub ProtectAll() Const PWORD...

Exception to password-protected document
Is it possible to password-protect the opening of a document for all users, EXCEPT one? Thanks Nope... The password to open files is an all or nothing proposition. Once open you can restrict the ability of different users in terms of the cells they are able to update. -- HTH... Jim Thomlinson "meems" wrote: > Is it possible to password-protect the opening of a document for all users, > EXCEPT one? > > Thanks ...

GP 10 Web Services -- Exceptions
Hi All, 1) While trying to configure the policies under the Microsoft Dynamics Security Console, if i select policy node i am getting an exception "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name : index" 2) I written an .NET application and i am trying fetch the customers in the company through web services reference, while executing the project i am getting an exception and if i saw the detailed exception through DynamicsWebServicesExceptionConsole its saying "Microsoft.Dynamics.Security.Non...

ado
c++ ado strcpy(sqlbuf, "select a, b, c, (case when (y=2) then d else null end) as d pRS->Open(sqlbuf,vtMissing, AdoNS::adOpenKeyset, AdoNS::adLockBatchOptimistic, -1); while(pRS->adoEOF == false) { //how do i read the values a, b, c and d?. //When i try to read the value d , i get the mismatch error. } -- Message posted via http://www.sqlmonster.com On Sat, 01 May 2010 12:07:31 GMT, "igg via SQLMonster.com" <u53571@uwe> wrote: >c++ ado >strcpy(sqlbuf, "select a, b, c, (case when (y=2) then d else null end) as >d >...

Importing ADO Persisted XML into Excel 2002
Is it possible to take a ADO.Recordset, which is persisted to XML and import that into Excel 2002 ? I'm using VB/VBA/VBS. I can find a range on a worksheet, and export it to MSPersist format pretty easy, so I assume the reverse can be done ? If so, does anyone have any sample code ? gadrin7@aol.com wrote: > Is it possible to take a ADO.Recordset, which is persisted to XML and > import that into Excel 2002 ? You should be able to just open it in Excel, it should render it somehow. You could re-open the recordset using ADO in VBA code then use Excel's CopyFromRecordset metho...

Disconnected ado recordset can not apply filter and sort
I created a disconnected ado recordset when a form is open: Private Sub Form_Open(Cancel As Integer) Dim formrst As ADODB.Recordset Set formrst = New ADODB.Recordset 'append 3 fields With formrst .ActiveConnection = Nothing .CursorLocation = adUseClient .Fields.Append "Fname", adBSTR .Fields.Append "Lname", adBSTR .Fields.Append "Age", adBigInt End With 'append some values to the recordset With formrst .Open .AddNew .Fields("fname") = "Tom" ...

Exception Rules
I am tying to set a rule that will forward all messages I recieve to another mailbox except for messages coming from 3 particular email addresses. I was able to set up a distribution list for these three addresses but can't find the ability to set a rule that will allow me to specuify all messages EXCEPT these. Any ideas? Thanks Create a blank rule (so not based on a template) and don't set any conditions. You'll get a warning that the rule will apply to all e-mails. Set the action to Forward and set the exception to the distributionlist you created. Note that the dist...

How to handle all unhandled exceptions when using Task Parallel Library?
I'm using the Task Parallel Library (TPL) in .NET 4.0. I want to centralize the handling logic of all unhandled exceptions by using the Thread.GetDomain().UnhandledException event. However, in my application, the event is never fired for threads started with TPL code, e.g. Task.Factory.StartNew(...). The event is indeed fired if I use the traditional Thread(threadStart).Start(). This MSDN article (http://msdn.microsoft.com/en-us/library/dd997415%28v=VS.100%29.aspx) suggests to use Task#Wait() to catch the AggregateException when working with TPL, but that is not I want b...

header and footer on every page except the first page?
how do i put header and footer on every page except the first page? One way: http://mcgimpsey.com/excel/subs/firstfooter.html In article <EBE1E559-C27E-47F9-BA16-0AA05EE9352E@microsoft.com>, marany <marany@discussions.microsoft.com> wrote: > how do i put header and footer on every page except the first page? ...