Microsoft KB Archive/907742

From BetaArchive Wiki
Knowledge Base


You may receive an "ADODB.Connection is not defined" error message when you try to create a new instance of an ADO connection in an ASP.NET-based application

Article ID: 907742

Article Last Modified on 11/28/2007



APPLIES TO

  • Microsoft ASP.NET 2.0



Bug #: 398546 (SQLBUDT)

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 use a Microsoft ActiveX Data Objects (ADO) object in a Microsoft ASP.NET-based application to connect to a Microsoft SQL Server database, you may receive the following error message:

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30002: Type 'ADODB.Connection' is not defined.

For example, this problem occurs when you create a new instance of an ADODB.Connection object or an ADODB.Recordset object. This problem also occurs when you pass a variable of type ADODB to a function.

Note In Visual Studio 2005, when you add a reference to the ADODB Primary Interop Assembly (PIA), Visual Studio 2005 automatically updates the Web.config file to insert the reference to the ADODB PIA. Therefore, this problem will not occur.

CAUSE

This problem may occur if the application does not explicitly reference the ADODB PIA. You must explicitly reference the ADODB PIA in the Web.config file so that the ASP.NET-based application can correctly compile the .aspx pages.

WORKAROUND

To work around this problem, you can modify the Web.config file for the server or you can modify the local copy of the Web.config file that is in the virtual directory where the .aspx pages are located.

To modify the Web.config file, follow these steps:

  1. Use the Global Assembly Cache tool (GacUtil.exe) to locate the global assembly cache (GAC) assembly registration for the ADODB PIA. To do this, run the following command at a command prompt:

    gacutil.exe /l adodb

    At the command prompt, you receive output that is similar to the following:

    The Global Assembly Cache contains the following assemblies:
    ADODB, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A, processorArchitecture=MSIL
    The cache of ngen files contains the following entries:
    Number of items = 1

  2. In the Web.config file, use the following code sample to add a reference to the ADODB PIA. In the code sample, replace the assembly details with the assembly details that you obtained in step 1.

    <configuration>
    <system.web>
    <compilation>
    <assemblies>
    <add assembly="ADODB, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A, processorArchitecture=MSIL"/>
    </assemblies>
    </compilation>
    </system.web>
    </configuration>
  3. Save the Web.config file.
  4. Restart the Microsoft Internet Information Services (IIS) service. To do this, run the following command at the command prompt:

    iisreset


Keywords: kbtshoot kbprb KB907742