Article ID: 832947
Article Last Modified on 6/15/2006
APPLIES TO
- Microsoft Visual Studio .NET 2003 Professional Edition
- Microsoft Visual Studio .NET 2003 Enterprise Architect
- Microsoft Visual Studio .NET 2003 Enterprise Developer
- Microsoft Visual Studio .NET 2003 Academic Edition
- Microsoft Visual Studio .NET 2002 Professional Edition
- Microsoft Visual Studio .NET 2002 Enterprise Architect
- Microsoft Visual Studio .NET 2002 Enterprise Developer
- Microsoft Visual Studio .NET 2002 Academic Edition
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 You receive unexpected errors when using ADO and ADO MD in a .NET Framework application
SYMPTOMS
When you execute a query from a Microsoft Visual Basic .NET application a second time, the Microsoft ActiveX Data Objects Library (ADODB) throws an exception, and you receive the following error message:
WORKAROUND
To work around this problem, use an early bound expression. To do this, locate the following code in step 6 of the "More Information" section of this article.
cn.QueryCustomers(intDisc, rs) '==>> exception here rs.ActiveConnection = Nothing
Replace this code with the following code.
rs = cmd.Execute(, New Object() {intDisc})
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section of this article.
MORE INFORMATION
Steps to reproduce the behavior
- Start Microsoft Visual Studio .NET.
- On the File menu, click New, and then click Project.
- Click Visual Basic Projects under Project Types, and then click Windows Application under Templates.
- In the Name box, type SampleWinApp, and then click OK.
- Add a Button control to the Form1.vb form.
Add the following code to the OnClick event procedure of the button.
Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Dim cmd As ADODB.Command Dim intDisc As Short Dim ts As Integer cn = New ADODB.Connection() cn.Open("provider=sqloledb;data source=legend;initial catalog=pubs;Integrated Security=SSPI") intDisc = 0 cmd = New ADODB.Command() With cmd .Name = "QueryCustomers" .CommandText = "Select top 5 stor_id as CustName, Discount from discounts where discount > ?" .CommandType = ADODB.CommandTypeEnum.adCmdText .Parameters.Append(.CreateParameter("DiscountIn", ADODB.DataTypeEnum.adDouble, ADODB.ParameterDirectionEnum.adParamInput)) .ActiveConnection = cn rs = New ADODB.Recordset() rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic cn.QueryCustomers(intDisc, rs) '==>> exception here rs.ActiveConnection = Nothing cmd.ActiveConnection = Nothing End With MsgBox("Successful")
- On the Project menu, click Add Reference.
- In the Add Reference dialog box, click the adodb component on the .NET tab, click Select, and then click OK.
- On the Debug menu, click Start to run the application.
- Click the button on the Form1 form. You receive a message that indicates that the code was executed successfully.
- Click the button a second time. The exception error message that is described in the "Symptoms" section appears.
REFERENCES
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
301075 HOW TO: Connect to a Database and Run a Command by Using ADO.NET and Visual Basic .NET
Keywords: kbbug kbmessagebox kbcominterop kbexcepthandling kbvs2002sp1sweep KB832947