Microsoft Knowledge Base Email Alertz

KBAlertz.com: (308499) - When you set a property value on an ActiveX Data Objects (ADO) object to a string value, you may encounter the following exception: Unhandled Exception: System.Runtime.InteropServices.COMException (0x800A0BB9): Arguments are of the wrong type, are out...

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: 308499 - Last Review: November 28, 2007 - Revision: 3.1

PRB: Unhandled Exception When You Set ADO Property to a String in Visual Basic .NET

This article was previously published under Q308499
For a Microsoft Visual C# .NET version of this article, see 309047  (http://kbalertz.com/Feedback.aspx?kbNumber=309047/EN-US/ ) .
Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:
840667   (http://kbalertz.com/Feedback.aspx?kbNumber=840667/ ) You receive unexpected errors when using ADO and ADO MD in a .NET Framework application

On This Page

SYMPTOMS

When you set a property value on an ActiveX Data Objects (ADO) object to a string value, you may encounter the following exception:
Unhandled Exception: System.Runtime.InteropServices.COMException (0x800A0BB9): Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

CAUSE

When you use ADO in the Microsoft .NET Framework with Component Object Model (COM) interop, ADO properties that formerly accepted either object references or string values now only support object references. As a result, when you try to set a property to a string value, an exception is thrown.

RESOLUTION

To set an ADO property that accepts either an object or a string to a string value in the .NET Framework, use the let_ methods that COM interop generates for imported assemblies. For sample code that demonstrates this, refer to the "More Information" section.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET.
  2. Create a new Windows Application project in Visual Basic .NET.
  3. Place a Button control on Form1, and change its Name property to btnTest.
  4. In Solution Explorer, right-click References, and then click Add Reference.
  5. On the COM tab in the Add Reference dialog box, click Microsoft ActiveX Data Objects 2.x Library. Click Select to add this reference to the Selected Components section, and then click OK.
  6. If no wrapper is found for the selected library, you receive a warning. Click Yes to generate a wrapper. The ADODB reference is added to the project references.
  7. Copy and paste the following code in the Code window after the "Windows Form Designer generated code" region:
    Private Sub btnTest_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles btnTest.Click
        Dim myConnString As String = _
            "Provider=SQLOLEDB.1;User ID=sa;password=sa;Initial Catalog=pubs;" & _
            "Data Source=mySQLServer"
        Dim mySelectQuery As String = "SELECT * FROM Authors"
        Dim myConnection as New ADODB.Connection()
        Dim myRecordset1 As New ADODB.Recordset()
        Dim myRecordset2 As New ADODB.Recordset()
        Try
            myConnection.ConnectionString = myConnString
            myConnection.open
    
            'Setting the ActiveConnection to a Connection object will work properly.
            myRecordset1.ActiveConnection = myConnection
            myRecordset1.Open(mySelectQuery)
            MessageBox.Show(myRecordset1(0).value)
    
            'Setting the ActiveConnection to a Connection string will fail.
            'Comment the next line of code, and uncomment the line that uses
            'the let_ActiveConnection to make the code work properly.
            myRecordset2.ActiveConnection = myConnString
            'myRecordset2.let_ActiveConnection(myConnString)
            myRecordset2.Open(mySelectQuery)
            MessageBox.Show(myRecordset2(0).value)
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        Finally
            myRecordSet1.Close()
            myRecordSet2.Close()
            myConnection.Close()
        End Try
    End Sub
    					
  8. Modify the connection string (myConnString) as appropriate for your environment.
  9. Save your project.
  10. From the Debug menu, click Start, and run your project.
  11. Click the button. When an ActiveConnection property is set to an object (in this case, the Connection object), it returns data properly.
  12. Set the ActiveConnection property to a Connection string. Notice that the code fails with the above-mentioned exception.
  13. Comment out the line that sets the ActiveConnection property to a Connection string. Uncomment the line that uses the let_ActiveConnection method.
  14. Run the project again. Notice that the data is returned properly.

APPLIES TO
  • Microsoft .NET Framework 1.1
  • Microsoft Visual Basic .NET 2002 Standard Edition
Keywords: 
kbprb KB308499
       

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