Link to home
Create AccountLog in
C#

C#

--

Questions

--

Followers

Top Experts

Avatar of Mikhail Sednenkov
Mikhail Sednenkov🇳🇱

The type name 'OleDbConnection' could not be found in the namespace 'System.Data.OleDb'
Hello.

I'd like to read FoxPro 9.0 database from within a C# application.
I have installed
    Microsoft Visual Studio Community 2019
    Microsoft OLE DB Provider for Visual FoxPro 9.0 (https://www.microsoft.com/en-us/download/details.aspx?id=14839)
on a
    Windows 7 64-bit OS
then rebooted it several times and created a C# console application ConsoleApp1

using System;
using System.Data;
using System.Data.OleDb;


namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            DataTable MyResultSet = new DataTable();
            var MyDbConn = new OleDbConnection(
                @"Provider=VFPOLEDB;Data Source=C:\\Users\\cbbe\\Desktop\\pup\\data\\;"
            );
            Console.WriteLine("Hello World!");
        }
    }
}

Open in new window


which fails to run because of an error

Severity  Code  Description Project File  Line  Suppression State
Error CS1069  The type name 'OleDbConnection' could not be found in the namespace 'System.Data.OleDb'. This type has been forwarded to assembly 'System.Data.OleDb, Version=4.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' Consider adding a reference to that assembly.  ConsoleApp1 C:\Users\cbbe\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 12  Active

Open in new window


and now when I go to the Project -> Add COM reference... there is

    No Items found for search term(s): 31bf3856ad364e35
    No Items found for search term(s): oledb
    No Items found for search term(s): 4.0.1.0

and when I type "ole" in the search field there is a

    ctv OLE Control module
    Microsoft OLE DB Provider for Visual FoxPro 7.0 Type Library
    Microsoft OLE DB Service Component 1.0 Type Library
    Microsoft OLE DB Simple Provider 1.5 Library
    OLE Automation 2.0
    OLE Automation 1.0
    OLE DB Errors Type Library
    oleprn 1.0 Type Library

which keeps me guessing:

1.
Where is the Microsoft OLE DB Provider for Visual FoxPro 9.0 I have installed earlier?

2.
What COM libraries should I link to my ConsoleApp1 to be sure I'm using the FoxPro 9.0 compatible OLE provider?

3.
Where can I find a decent documentation for all these wonderful linkable components?

Thank you for your patience reading this. There's also a screenshot illustrating my problem.
User generated image

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Pavel CelbaPavel Celba🇨🇿

The VFPOLEDB driver is installed in C:\Program Files (x86)\Common Files\System\Ole DB\ folder obviously. You may find the path in Windows Registry.
No extra COM libraries are necessary, .NET knows where to look for the driver it it is installed properly.
Documentation? Search the web for existing code samples. Intellisense can also help a lot.

Important here is the fact the VFPOLEDB provider is 32 bit only so you also need 32 bit .NET Framework components.
If you see the location of System.Data assembly in C:\Program Files (x86)\ folder which is derived for 32 bit applications then it should work.

Following code works for me w/o issues.User generated image

ASKER CERTIFIED SOLUTION
Avatar of it_saigeit_saige🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of it_saigeit_saige🇺🇸

@pcelba, the OP is using a .NET core console application which is why they get the error about System.Data.OleDb.

-saige-

Avatar of ste5anste5an🇩🇪

Important here is the fact the VFPOLEDB provider is 32 bit only so you also need 32 bit .NET Framework components.
This also means, that you need to select 32bit as target in the projects settings..

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of it_saigeit_saige🇺🇸

Good point.  ;)

-saige-

Avatar of it_saigeit_saige🇺🇸

I'd also point out, that I, personally, would not use the COM reference unless it is absolutely required.  The libraries in System.Data and System.Data.OleDb are more than capable.

-saige-

SOLUTION
Avatar of Pavel CelbaPavel Celba🇨🇿

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of Pavel CelbaPavel Celba🇨🇿

JFY, I've just installed .NET SDK 5.0 for x86 platform and if you select the Target platform as x86 in VS 2019 then VFPOLEDB seems to be working correctly (tested on one simple SELECT command).

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Mikhail SednenkovMikhail Sednenkov🇳🇱

ASKER

pcelba, as for now I copied your code and getting an error

System.Data.OleDb.OleDbException: 'Function is not implemented.'

Open in new window

on a
MyAdapter.Fill(ds);

Open in new window

line.

But that not bothers me since I'm not sure I want to use the System.Data.OleDb at all. I was hoping to create an ActiveXObject("ADODB.Connection") object and then inspect it using debugger or something to see it's actual API interface (functions, objects, constants, etc.)

As far as I understand, System.Data.OleDb is a C#-specific package that doesn't exists outside of C# (I mean the API). Please correct me if I'm wrong.

Avatar of Pavel CelbaPavel Celba🇨🇿

If you mean this code:
using System;
using System.Data;
using System.Data.OleDb;

namespace ConsoleApp4CoreVFPOLEDB
{
    class Program
    {
        static void Main(string[] args)
        {
            //DataTable MyResultSet = new DataTable();
            var MyDbConn = new OleDbConnection(
                @"Provider=VFPOLEDB;Data Source=d:\\w7\\VFPApp\\Testy\\;"
            );
            MyDbConn.Open();
            var MyAdapter = new OleDbDataAdapter("SELECT * FROM Orders", MyDbConn);
            DataSet ds = new DataSet();
            MyAdapter.Fill(ds);
            for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                Console.WriteLine("OrderID {0}, Shipping Zone: {1}",
                    ds.Tables[0].Rows[i].ItemArray[0], ds.Tables[0].Rows[i].ItemArray[28]);
            }
            Console.WriteLine("Total {0} order(s)", ds.Tables[0].Rows.Count);
            Console.WriteLine("Hello World 2!");
            //Console.ReadKey();
        }
    }
}

Open in new window

then I believe you have your path and your table in the SELECT command.
I am also using this project properties:
User generated image
User generated image

Avatar of it_saigeit_saige🇺🇸

System.Data.OleDb is not C# specific:User generated image
Imports System
Imports System.Data
Imports System.Data.OleDb

Module Program
    Sub Main(args As String())
        Dim connection = New OleDbConnection("Provider=VFPOLEDB;Data Source=C:\Program Files (x86)\Microsoft Visual FoxPro OLE DB Provider\Samples\Northwind\;")
        Dim adapter = New OleDbDataAdapter("SELECT FirstName, LastName from Employees", connection)
        Dim ds = New DataSet()
        adapter.Fill(ds)
        For Each row In ds.Tables(0).Rows.Cast(Of DataRow)
            Console.WriteLine($"{row("FirstName")} {row("LastName")}")
        Next
        Console.ReadLine()
    End Sub
End Module

Open in new window

Produces the following output:User generated image
HTH,

-saige-

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Pavel CelbaPavel Celba🇨🇿

ADODB.Connection object is described in Microsoft Docs  but you don't need it in .NET 5.0 application. System.Data.OleDb is also described in doc and it provides Intellisense in VS2019.


Avatar of Mikhail SednenkovMikhail Sednenkov🇳🇱

ASKER

pcelba, you're right since this code works fine

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.OleDb;


namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var dbconn = new OleDbConnection(@"Provider=VFPOLEDB;Data Source=C:\\Program Files (x86)\\Microsoft Visual FoxPro OLE DB Provider\\Samples\\Northwind\\;");
            dbconn.Open();
            var adapter = new OleDbDataAdapter("SELECT FirstName, LastName from Employees", dbconn);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                Console.WriteLine("FirstName {0}, LastName: {1}",
                      ds.Tables[0].Rows[i].ItemArray[0], ds.Tables[0].Rows[i].ItemArray[1]);
            }
            Console.WriteLine("Total {0} record(s)", ds.Tables[0].Rows.Count);
            Console.WriteLine("Hello World 4!");
            Console.ReadKey();
        }
    }
}

Open in new window

and prints

C:\Users\cbbe\source\repos\ConsoleApp4\ConsoleApp4\bin\Debug>ConsoleApp4.exe
FirstName Nancy     , LastName: Davolio
FirstName Andrew    , LastName: Fuller
FirstName Janet     , LastName: Leverling
FirstName Margaret  , LastName: Peacock
FirstName Steven    , LastName: Buchanan
FirstName Michael   , LastName: Suyama
FirstName Robert    , LastName: King
FirstName Laura     , LastName: Callahan
FirstName Anne      , LastName: Dodsworth
Total 9 record(s)
Hello World 4!

Open in new window


there's something probably wrong with the query.

Avatar of it_saigeit_saige🇺🇸

The C# can also be written as:
using System;
using System.Data;
using System.Data.OleDb;
using System.Linq;

namespace EE_Q29201752
{
    class Program
    {
        static void Main(string[] args)
        {
            var connection = new OleDbConnection(@"Provider=VFPOLEDB;Data Source=C:\Program Files (x86)\Microsoft Visual FoxPro OLE DB Provider\Samples\Northwind\;");
            var adapter = new OleDbDataAdapter("SELECT FirstName, LastName from Employees", connection);
            var ds = new DataSet();
            adapter.Fill(ds);
            foreach (var row in ds.Tables[0].Rows.Cast<DataRow>())
            {
                Console.WriteLine($"FirstName: {row["FirstName"]}, LastName: {row["LastName"]}");
            }
            Console.WriteLine($"Total {ds.Tables[0].Rows.Count} record(s)");
            Console.ReadLine();
        }
    }
}

Open in new window

Which produces the following output:User generated imageHTH,

-saige-

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Mikhail SednenkovMikhail Sednenkov🇳🇱

ASKER

it_saige,
System.Data.OleDb is not C# specific
so it's .NET Framework specific?

Avatar of it_saigeit_saige🇺🇸

I'd actually say it is .NET specific since Framework is being dropped from the name as of .NET 5.  However in the case of System.Data.OleDb, it can be used by a few different frameworks:User generated image
-saige-
C#

C#

--

Questions

--

Followers

Top Experts

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).