?
Solved

Help with ADO please

Posted on 2009-02-20
27
Medium Priority
?
236 Views
Last Modified: 2013-12-17
In Visual Studio 2008, I am trying to create a class that uses ADODB to access a Sql Server. I did this quite succesfully in a C# program project. But now i'm having dificulty doing the same within a C# Class in an asp.net project. The dificult is in the 'Using' statement at the top of the file. In the C# project, I have a line:

Using ADODB;

But this is not seem to be available in my asp.net project. So when I try and declare an ADODB.connection, the compiler says the type or namespace is missing. Which 'Using' statement should I use in my asp.net project?

Ian

0
Comment
Question by:ipendlebury
  • 13
  • 12
  • 2
27 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 1000 total points
ID: 23695273
you need to add a reference to the COM ADO object.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23695276
Why don't you use system.data.sqlclient instead ?
0
 

Author Comment

by:ipendlebury
ID: 23695299
ipaulino: I had already tried that. It didn't help. I think I tried everything that intellisense showed.

emoreau: I'm a complete noob. I would like to try your suggestion, but I dont know how to.
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 48

Expert Comment

by:jpaulino
ID: 23695316
But you need to use ADODB to access a Sql Server ? SqlClient class provides a better way and optimized methods to access SQL Server.
0
 

Author Comment

by:ipendlebury
ID: 23695336
maybe but I have a routines written which use ADODB. I would like to continue using them
0
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 1000 total points
ID: 23695389
Ok, then you need to do what emoreau suggested.
Menu WebSite - Add References, COM tab and select Microsoft ActiveX Data Objects 2.X Library
0
 

Author Comment

by:ipendlebury
ID: 23695416
Ok thanks, I did that, but it still will not accept: Using ADODB;

Should I be using a different 'Using' statement?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 23695719
have you tried the code from http://support.microsoft.com/kb/308611?

Maybe that the ADODB object cannot be used with using because it does not implement the IDisposable interface
0
 

Author Comment

by:ipendlebury
ID: 23695749
That example illustrates using ADODB in a c# program. I said at the start of this thread that I can do this already. What I can't do is use it in asp.net project. I dont know what the difference is.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23695864

Now I'm confused !!! In a asp.net project you use the same way OR are you using in the html page ?

In the html page you have to do:

<%@ Import Namespace="ADODB" %>  
 
Another thing that I have noticed is that C#, as you know, is case sensitive. If you're using in the code behind you have to declare:

using ADODB;

and not

Using ADODB;
0
 

Author Comment

by:ipendlebury
ID: 23695907
This is a Class file in my App_Code folder. The aspx pages will call functions from within this Class. My  .CS file has multiple 'using' statements at the top. But the intellisense will not allow: using ADODB like I could use in the C# program project.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23695942
Have you added the reference ?
Do you have something like this ?

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ADODB;
 
/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
	public Class1()
	{
		//
		// TODO: Add constructor logic here
		//
	}
}

Open in new window

0
 

Author Comment

by:ipendlebury
ID: 23695969
Yes that'sexactly what I have, but the: using ADODB; on line 12 generates an error.

he type or namespace name 'ADODB' could not be found (are you missing a using directive or an assembly reference?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23696018
That indicates that you didn't add a reference to Microsoft ActiveX Data Objects 2.X Library.
Check on View - Property Pages - References and look if you have a reference to Interop.AdoDB (thats from Microsoft ActiveX Data Objects 2.X Library)
0
 

Author Comment

by:ipendlebury
ID: 23696114
I cant seem to get References visible in the Properities pages. However I noticed that when I previously clicked to add theActiveX Data Objects, a file called Interop.ADOR.dll appeared in the Bin folder in the Solution Explorer.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23696165
You must have Interop.ADODB.dll in the References folder.
 
Don't you have in the Property Pages a references option ?
0
 

Author Comment

by:ipendlebury
ID: 23696234
No I can only find the page that gives basic properties for my Class file. There's nothing else there. I was looking in the menus for how to make other things visible.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23696265
Check on the menu View - Property Pages - References
0
 

Author Comment

by:ipendlebury
ID: 23696304
Properties Pages is greyed out in the View Menu. Sorry I'm new to Visual Studio. So I dont know why this is.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23696324
That's because the page is running. Stop the page and way a few second or right click on the project root in the soluction explorer and selec property pages.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23696333
Sorry, typo
" ... and wait a few seconds ..."
0
 

Author Comment

by:ipendlebury
ID: 23696352
No i have never run any pages yet. Because of this problem, i've not been able to compile succesfully
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23696367
"right click on the project root in the soluction explorer and select property pages."
0
 

Author Comment

by:ipendlebury
ID: 23696390
Ah ok. That worked. It shows these references.....

Interop.ADOR
System.core
System.Data.DataSetExtensions
System.WebExtensions
System.Xml.Linq
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 23696465
Remove the Interop.ADOR and add a new reference to Microsoft ActiveX Data Objects 2.X Library (Microsoft ActiveX Data Objects 2.8 Library for example).
 
Don't forget that this was an original suggestion from emoreau
0
 

Author Comment

by:ipendlebury
ID: 23696638
I deleted Interop.ADOR and added Microsoft ActiveX Data objects 2.8 (which put Interop.ADOR back again) It still generated the same error. It was ActiveX 2.8 that I addes originally.

 Then I spotted something......

When adding the Reference, I noticed that the .NET tab had 'adodb' near the top. So I added this and the compilation error went away. I have not got enough routines into my class yet in order to test it. But have I just done something dumb? Or have I fixed it?
0
 

Author Comment

by:ipendlebury
ID: 23701160
With that reference added, my project compiles successfully, but I cannot open a connection to the SqlServer. In desperation, I tried the Active Data Objects 2.8 reference again. This time I found the reference was accepted and my project compiled. So i dont understand why I had such difficulty yesterday.

So my project now compiles. So I will thank you for your efforts and close this thread. I will ask a new question about why I cannot open a connection.

Ian

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question