Microsoft Knowledge Base Email Alertz

KBAlertz.com: (308651) - Managed providers can raise several exceptions. To obtain more detailed information about the cause, you need access to provider-specific error information. This article shows how to gather this information. Requirements The following list outlines...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 308651 - Last Review: August 31, 2005 - Revision: 4.0

How to obtain underlying provider errors by using ADO.NET in Visual C++ .NET

This article was previously published under Q308651
For a Microsoft Visual Basic .NET version of this article, see 308043  (http://kbalertz.com/Feedback.aspx?kbNumber=308043/ ) .
For a Microsoft Visual C# .NET version of this article, see 308650  (http://kbalertz.com/Feedback.aspx?kbNumber=308650/ ) .

This article refers to the System::Data::OleDb namespace in the Microsoft .NET Framework Class Library.

On This Page

SUMMARY

Managed providers can raise several exceptions. To obtain more detailed information about the cause, you need access to provider-specific error information. This article shows how to gather this information.

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
  • Microsoft .NET Framework
  • Microsoft Visual C++ .NET
This article assumes that you are familiar with the following topics:
  • Exceptions and error handling
  • Microsoft OLE DB

Technique description

You must wrap your code in a "try... catch" block to catch the exception and process the error collection from the OLEDBException.

Create project and add code

  1. Create a new Managed C++ application. Name the project ProviderError.
  2. Open the ProviderError.CPP file. Copy the following code and paste it in to replace the default code built in by Microsoft Visual Studio .NET:
    
    #include "stdafx.h"
    #using <mscorlib.dll>
    #using <System.dll>
    #using <System.Data.dll>
    
    using namespace System;
    using namespace System::Data::OleDb;
    
    // This is the entry point for this application
    #ifdef _UNICODE
    int wmain(void)
    #else
    int main(void)
    #endif
    {
            OleDbConnection *myCn = new OleDbConnection("Provider=SQLOLEDB.1;Data Source=MyWrongServerName");
            try
    	{
                myCn->Open();
    	}
            catch(OleDbException *ex)
    	{
                Int32 i;
                for (i = 0; i <= ex->Errors->Count - 1; i++)
    	   {
    				Console::WriteLine("Index # {0} \n Message: {1} \n Native: {2}" 
    					"\n Source: {3} \n SQL: {4} \n", i.ToString(), ex->Errors->Item[i]->Message, 
    					ex->Errors->Item[i]->NativeError.ToString(), ex->Errors->Item[i]->Source, 
    					ex->Errors->Item[i]->SQLState);
    	   }
    	}
    
    	return 0;
    }
  3. On the Debug menu, click Run without Debugging to run the application. A console window that contains the provider error should appear after about 10 to 15 seconds.

Troubleshooting

If you have a server called "MyWrongServerName", you may not get an error message.

APPLIES TO
  • Microsoft ADO.NET 1.1
  • Microsoft ADO.NET 1.0
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
Keywords: 
kbhowtomaster kbsystemdata KB308651
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please