BUG: An "Object reference not set to an instance of an object" error occurs when you try to access data by using ADO Interop on an ASP.NET page

Article translations Article translations
Article ID: 810098 - View products that this article applies to.
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
Expand all | Collapse all

On This Page

SYMPTOMS

On a computer that has Microsoft .NET Framework 1.0 installed (and that does not have Microsoft Visual Studio .NET installed), when you try to access data using ADO Interop on an ASP.NET page that resides at an identical site and that is hosted on the same computer, you may receive the following error message:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

RESOLUTION

To resolve this problem, register the Adodb.dll file in the global assembly cache (GAC). On a computer where only the .NET Framework is installed, the file Gacutil.exe does not exist.. Either obtain the gacutil file by installing Microsoft .NET Framework SDK, or create a Visual Studio.NET setup project that uses the installer to install the correct components.

To register Adodb.dll in the GAC, follow these steps:
  1. Click Start and then click Run.
  2. In the Run dialog box, type the following command, and then click OK:
    C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\gacutil /i C:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new Microsoft Visual C# project named ADORefError. By default, WebForm1.aspx appears.
  2. On the Project menu, click Add Reference.
  3. On the .NET tab, select adodb from the drop-down list.
  4. Click Select, and then click OK.
  5. Drag a Label control from the toolbox to WebForm1.aspx.
  6. In Solution Explorer, right-click WebForm1.aspx, and then click View Code.
  7. Paste the following code in the Page_Load event:

    Note You must change the User Id <user name> value to an account that has the appropriate permissions to perform these operations on the database.
    		//Create ADODB Objects
    		ADODB.Connection oConn = new ADODB.ConnectionClass();
    		ADODB.Recordset oRS = new ADODB.RecordsetClass();
    		
    		//Change Connection String depending on your SQL Server 
    		string strConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=<username>;Initial Catalog=pubs;Data Source=Your SQLServer Name";
    			
    		oConn.Open(strConn,"","",0);
    		object objRecs = 100;
    		oRS = oConn.Execute("select au_Id, au_lname from authors", out objRecs,0);
    
    		//Error is generated by referencing the Fields collection
    		Label1.Text = oRS.Fields["au_id"].Value.ToString();
    
    		//Close all connections
    		oRS.Close();
    		oConn.Close();
    
    		//Release COM Objects
    		oRS = null;
    		oConn = null;
    
    
  8. Copy Adodb.dll (from the C:\Program Files\Microsoft.NET\Primary Interop Assemblies\ folder) to the Bin folder of the ADORefError application.
  9. On the Build menu, click Build Solution.
  10. Start Microsoft Internet Explorer, and then browse to WebForm1.aspx by specifying the following URL, where IISServerName is the name of your Microsoft Internet Information Services (IIS) server:
    http://IISServerName/ADORefError/WebForm1.aspx
  11. Identify a test computer that has the .NET Framework installed (without Microsoft Visual Studio .NET). In IIS, create two virtual directories and name them Test1 and Test2.
  12. Create two identical sites: from the ADORefError folder, copy WebForm1.aspx and the Bin folder to the Test1 and Test2 folders on the test computer.
  13. Start Microsoft Internet Explorer and browse to WebForm1.aspx of Test1 site by specifying the following URL, where IISServerName is the name of your Microsoft Internet Information Services (IIS) server:
    http://IISServerName/Test1/WebForm1.aspx
  14. Start another instance of Microsoft Internet Explorer and browse to WebForm1.aspx of Test2 site by specifying the following URL:
    http://IISServerName/Test2/WebForm1.aspx
  15. When you access WebForm1.aspx of Test2, you receive the error message as detailed in the SYMPTOMS section.

REFERENCES

For more information about registering .dll files in the GAC, visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/aa309379(VS.71).aspx

Properties

Article ID: 810098 - Last Review: September 17, 2011 - Revision: 7.0
APPLIES TO
  • Microsoft ASP.NET 1.0
  • Microsoft ASP.NET 1.1
  • Microsoft ADO.NET 2.0
  • Microsoft ActiveX Data Objects 2.7
  • Microsoft ADO.NET 1.1
Keywords: 
kbtshoot kberrmsg kbbug kbwebforms KB810098

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com