Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Problem with 'Microsoft.ACE.OLEDB.12.0' provider !

$
0
0

Dear Friend,

I am getting problem with my asp.net page where I want to import data from an excel file to sql server 2008 R2. If I run the page from my development environment then everything is ok. Data imported successfully. But when I call from network pc by ip address and port(like 172.16.111.205:8080) then It shows "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. "

I have installed AccessDatabaseEngine 32 bit. But no luck. I am using Visual Studio 2010, SQL Server 2008 R2, Office 2010 32 bit and my OS is Windows server 2008 R2 64 bit. Below I am inserting my code If that help you to solve my problem.

Please help. Thanks in advance.

public void cleare_DB()
    {
        try
        {
            Fn.CreateConn();
            SqlCommand cmdSqlUpdate = new SqlCommand(@"DELETE FROM TrackInfo", Fn.cnDB);            
            int result = cmdSqlUpdate.ExecuteNonQuery();

        }
        catch (Exception ex)
        {
            lblError.Text = ("Error:" + ex);
        }
        finally
        {
            Fn.CloseConn();
        }
    }
    protected void btnImport_Click(object sender, EventArgs e)
    {
        cleare_DB();

        try
        {         
            string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", "E:\\ROSC II\\ROSC\\MO-Track\\MO-Track.xlsx");

            // Create Connection to Excel Workbook
            using (OleDbConnection connection =
                         new OleDbConnection(excelConnectionString))
            {
                OleDbCommand command = new OleDbCommand
                        ("Select * FROM [Sheet1$]", connection);

                connection.Open();

                // Create DbDataReader to Data Worksheet
                using (DbDataReader dr = command.ExecuteReader())
                {

                    // SQL Server Connection String
                    string sqlConnectionString = @"Data Source=172.16.111.205;Initial Catalog=MOTracking;User ID=sa;Password=Nmis1234";

                    // Bulk Copy to SQL Server
                    using (SqlBulkCopy bulkCopy =
                               new SqlBulkCopy(sqlConnectionString))
                    {
                        bulkCopy.DestinationTableName = "TrackInfo";
                        bulkCopy.WriteToServer(dr);
                        Label1.Text = "The data has been exported succefuly from Excel to SQL";
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }        
    }


Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>