• Hello and welcome to our new forums. We upgraded our forum sites to a more robust and modern system which we hope you will enjoy. Be sure to check out your profile by clicking the button on the top right and configure your preferences, signature, time zone, avatar, etc. as you wish. If you need help with using this new forum'ware try the help link on the bottom right.

    Click here to review your account now.

Link Access to C#

peterhw

Member
Joined
Jan 29, 2019
Messages
8
Location
Scotland
Programming Experience
10+
Just created a database in access and would like to retrieve data from a C# windows forms application.
My first attempt failed with unrecognized database format.
I sort of think I am missing something very simple like 'using System.xxxxxx
The database seems fine - i.e. can click on the address used below (database file name) and it opens
Any help appreciated


500


Windows 10 Pro, Visual Studio 17 V15.9.6. Microsoft Office Pro 2016
 
Last edited:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,166
Location
Sydney, Australia
Programming Experience
10+
The way you're doing it, it is using the Jet OLE DB provider, which only supports MDB files. I just tried adding an ACCDB file to a project in VS 2017 and then opening it from the Server Explorer and it told me that the ACE OLE DB provider, which is required for ACCDB files, is not installed. That is presumably because VS is running in a 64-bit process and only the 32-bit version of ACE is installed. Either that or it's because I installed Office 365 from the Microsoft Store and that affects the registration of ACE. I think that that may be the case, because I tried connecting in code and got the same error message. How EXACTLY did you install Office? It may be that you need to install ACE separately.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,166
Location
Sydney, Australia
Programming Experience
10+
If you have Office 365, this seems relevant:


That suggests that you can install the 2013 version of ACE without issue. You will almost certainly want the 32-bit version, because most Office users will have installed 32-bit Office, so your app will need to support that for maximum compatibility. You may want to create a 64-bit version too. I believe that it is possible to have both 32-bit and 64-bit ACE installed on the same machine these days but I'm not sure whether there are any hoops to jump through to make it work, so that would be something to read up on.

I'm just downloading 32-bit ACE 2013 but I won't install it immediately. If you have further issues, post back and I may be able to take a closer look.
 

peterhw

Member
Joined
Jan 29, 2019
Messages
8
Location
Scotland
Programming Experience
10+
If you have Office 365, this seems relevant:


That suggests that you can install the 2013 version of ACE without issue. You will almost certainly want the 32-bit version, because most Office users will have installed 32-bit Office, so your app will need to support that for maximum compatibility. You may want to create a 64-bit version too. I believe that it is possible to have both 32-bit and 64-bit ACE installed on the same machine these days but I'm not sure whether there are any hoops to jump through to make it work, so that would be something to read up on.

I'm just downloading 32-bit ACE 2013 but I won't install it immediately. If you have further issues, post back and I may be able to take a closer look.
Many thanks - looks like this is the area to focus on.
I have also tried to install code directly and get messages like 'the OLEDB 12 provider is not recognized on the local machine.'
Will spend more time tomorrow (I am in UK)
 

peterhw

Member
Joined
Jan 29, 2019
Messages
8
Location
Scotland
Programming Experience
10+
Many thanks - looks like this is the area to focus on.
I have also tried to install code directly and get messages like 'the OLEDB 12 provider is not recognized on the local machine.'
Will spend more time tomorrow (I am in UK)
Managed to make an ACCESS connection from Visual Studio 17 using C#.
The following link provides an an Microsoft Access data base engine.
This link provides 32 & 64 bit editions.
Despite having a 64 bit machine - MicroSoft OFFICE Pro appears to be 32 (though I do understand somewhere there are 64 bit versions)
one I had downloaded and installed the above then I managed a successfull connection using the following code

C#:
        private void frmDashboard_Load(object sender, EventArgs e)
        {
            try
            {
                OleDbConnection my_connection = new OleDbConnection();
                //Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HOME\Documents\BankTransactions.accdb;
                //Persist Security Info = False;
                string mystring = @"Provider =Microsoft.ACE.OLEDB.12.0;";
                mystring = mystring + @"Data Source = C:\Users\HOME\Documents\BankTransactions.accdb;";
                mystring = mystring + @"Persist Security Info = False;";
                my_connection.ConnectionString = mystring;;
                my_connection.Open();
                C2A.Text = "DataBase Connected";
                my_connection.Close();
            }catch (Exception ex)
            {
                MessageBox.Show("Failed to Connect \r\n+++++++++++++++++++++++++++++++++++++++++++++++\r\n"+ex);
            }
        }
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,166
Location
Sydney, Australia
Programming Experience
10+
Recent versions of Office have come in both 32-bit and 64-bit editions. Generally speaking, those on 64-bit machines should install 64-bit applications if they are available but Microsoft recommend installing 32-bit Office unless you have specific need of one of the few genuine extra features that 64-bit Office provides, e.g. support for very large Excel spreadsheets. The reason for that is the huge range of Office add-ins that has built up over the years will not be supported in 64-bit Office. That means that, as a .NET developer writing applications to connect to Access databases, you need to make sure that your app runs in a 32-bit process if you want to support the largest number of users. If you want to support those with 64-bit Office as well then you need to compile a second edition of your app.

By the way, don't build a connection string like that. If you're going to do it in pieces then use an OleDbConnectionStringBuilder.

Also, while I haven't explicitly tested, you should probably be able to create a typed DataSet now as you were originally trying to do. If choosing the Access item you did before doesn't give you the option to change from Jet to ACE, try selecting the <other> item instead and see if that works. I've had non-365 editions of Office installed before and I'm sure that I've created typed DataSets from ACCDB files before.
 

NETANEL.S

Member
Joined
Feb 14, 2019
Messages
21
Programming Experience
3-5
you can try download this software:

after do you download, you need to extract file from zip and run this exe file and install it.
after these actions you need to select access file:
503

after this do you need to click next and select create dump file
504

after this you select next and select all tables
505
select next and after this click run now>>
do you recieve sql file.

after this you need to move sql file to mssql(description in clip) :
 

Attachments

Top Bottom