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 (907742)



The information in this article applies to:

  • Microsoft ASP.NET 2.0

Bug #: 398546 (SQLBUDT)

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


Modification Type:MajorLast Reviewed:10/11/2005
Keywords:kbtshoot kbprb KB907742 kbAudITPRO kbAudDeveloper