none
The type or namespace name OleDb does not exist in the namespace System.Data(are you missing an assemly reference)? RRS feed

  • Question

  • I am having the compile error 'The type or namespace name OleDb does not exist in the namespace System.Data(are you missing an assembly reference)?' I am using visual studios 2008 and I am seeing the name space System.Data.OleDb when I look it up in the reference tree within the solution explorer window under System.Data. The compiler however is not picking it up. Can someone help me solve this? I have already ruled out case sensitivity.

    Thanks
    • Edited by Sephora Monday, July 6, 2009 7:16 PM
    Monday, July 6, 2009 7:02 PM

Answers

All replies

  • Do you have "using System.Data.OleDb" at the top of your project.class?
    Monday, July 6, 2009 7:16 PM
  • yup. I have using System.Data and directly under it I have System.Data.OleDb;

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.OleDb;       //not finding this namespace
    using System.Text;

    namespace TestingdataApp
    {
        class DataTry
        {
            string myConnectionString = "Provider=SQLOLEDB.1;Data Source=telib;uid = sysadm;pwd=sysadm";
            string mySelectQuery = "SELECT BA_ADDR1 FROM BOR_ADDR";

            static void main(string[] args)
            {

                OleDbConnection conn = new OleDbConnection(myConnectionString);
                OleDbCommand myCommand = new OleDbCommand(mySelectQuery, conn);
                conn.Open();
                OleDbDataReader myReader;
                myReader = myCommand.ExecuteReader();
                // Always call Read before accessing data.
                while (myReader.Read())
                {
                    Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
                }
                // always call Close when done reading.
                myReader.Close();
                // Close the connection when done with it.
                conn.Close();
            }
        }
    }


    Monday, July 6, 2009 7:19 PM
  • Try dropping the reference and re-adding it.
    Monday, July 6, 2009 7:40 PM
  • I found it. Apparently the OleDb namespace only applies within an executable project. I was trying to apply it within an Output project. Thanks for responding
    Monday, July 6, 2009 7:52 PM
  • OleDb classes can be used in any kind of project, you only need to reference System.Data.dll in your project. I am glad you solved this issue.


    Postings are provided "As Is" with no warranties and confer no rights.
    Monday, July 6, 2009 10:20 PM
    Moderator
  • Hi Sephora, i too am finding the same problem as yours. As per your observation, OleDb doesn't work with Output project, how did you resolve it? Or what did you use instead of using
    System.Data.OleDb;
    to connect to the database??

    Thanks in advance.
    Wednesday, September 2, 2009 10:30 AM
  • Hi Greeshma;

    I used a windows class library to write most of my database code. Hope this helps :-)
    Wednesday, September 2, 2009 11:12 AM
  • Hi Sephora,
    Thanks for the quick reply. Can you post the relevant piece of code used to connect to the database using 'windows class library'? Thanks again.
    Wednesday, September 2, 2009 11:15 AM
  • I hope this is helpful, as my code is quite complicated now. But basically i re-wrote the above lines of code within a windows class library. At the time I was trying to write the code within the console application for the windows smart device and i have learnt now that the smart-device applications do not have the memory capacity to run those type of references directly. If you try to use System.Data.OleDb in a console application ( that is the template that would normally carry the main method) the namespace would not be recognised and that is what I was doing above to get the error.

    If however you use one of the windows class libraries, the one without the main methods, System.Data.OleDb is recognised.  When I finished writing my database methods using the class libraries, i then opened and wrote a windows console application (using the console application template) and referenced my database code (by adding  the corresponding dll via solution explorer) to test the database methods.

    If you tried this and it still does not work, then something else is wrong and you may need to give more information.
    Wednesday, September 2, 2009 11:57 AM
  • oh

    Smart Device = Output project

    Windows = executable project

    this is what I meant when i used the terms within the earlier posts.
    Wednesday, September 2, 2009 11:59 AM
  • That was really of great help, thanks a ton!!!!!!!!!!!!
    Wednesday, September 2, 2009 12:10 PM
  • had same problem

    i declared the name space in my web.config

    changed

    <namespaces>
            <clear />
            <add namespace="System" />
            <add namespace="System.Collections" />
            <add namespace="System.Collections.Specialized" />
            <add namespace="System.Configuration" />
            <add namespace="System.Text" />
            <add namespace="System.Text.RegularExpressions" />
            <add namespace="System.Web" />
            <add namespace="System.Web.Caching" />
            <add namespace="System.Web.SessionState" />
            <add namespace="System.Web.Security" />
            <add namespace="System.Web.Profile" />
            <add namespace="System.Web.UI" />
            <add namespace="System.Web.UI.WebControls" />
            <add namespace="System.Web.UI.HtmlControls" />
            <add namespace="System.Web.UI.WebControls.WebParts" />
            <add namespace="System.Data" />
           <add namespace="System.Data.oledb" />
          </namespaces>

    LAST LINE TO  <add namespace="System.Data.OleDb" /> 

    apparently case sensitive




    • Edited by רומן Sunday, April 9, 2017 3:42 PM
    Sunday, April 9, 2017 3:40 PM