'Cannot create an instance of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)". in winforms
i keep getting this error when I click the btn. the query is running fine in SSMS btw but throwing the above error in winforms. would really appreciate the help. been stuck at it all day. i read up on some other questions and appropriately applied all the solutions like the sp configures and setting oledb properties and managed to get it working on ssms but unable to get it to work on winforms error screenshot
try
{
con.Open();
string str1 = "use "+database;
// 1st
string step1_1 = "EXEC sp_configure 'show advanced options', 1";
string step1_2 = "RECONFIGURE";
string step1_3 = "EXEC sp_configure 'ad hoc distributed queries', 1";
string step1_4 = "RECONFIGURE";
// 2nd
string step2_1 = "EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.12.0', N'AllowInProcess', 1";
string step2_2 = "EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.12.0', N'DynamicParameters', 1";
//3rd
string step3_1 = "SP_CONFIGURE 'show advanced options', 1";
string step3_2 = "RECONFIGURE";
string step3_3 = "SP_CONFIGURE 'Ad Hoc Distributed Queries', 1";
string step3_4 = "RECONFIGURE";
string str2 = "select * INTO ali FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0; Database=C:\\xlsx\\foursheet.xlsx', [Sheet2$])";
SqlCommand cmd1 = new SqlCommand(str1, con);
SqlCommand xaa = new SqlCommand(step1_1, con);
SqlCommand xbb = new SqlCommand(step1_2, con);
SqlCommand xcc = new SqlCommand(step1_3, con);
SqlCommand xdd = new SqlCommand(step1_4, con);
SqlCommand xee = new SqlCommand(step2_1, con);
SqlCommand xff = new SqlCommand(step2_2, con);
SqlCommand aa = new SqlCommand(step3_1, con);
SqlCommand bcaa = new SqlCommand(step3_2, con);
SqlCommand bb = new SqlCommand(step3_3, con);
SqlCommand cc = new SqlCommand(step3_4, con);
SqlCommand cmd2 = new SqlCommand(str2, con);
cmd1.ExecuteNonQuery();
xaa.ExecuteNonQuery();
xbb.ExecuteNonQuery();
xcc.ExecuteNonQuery();
xdd.ExecuteNonQuery();
xee.ExecuteNonQuery();
xff.ExecuteNonQuery();
aa.ExecuteNonQuery();
bcaa.ExecuteNonQuery();
bb.ExecuteNonQuery();
cc.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
MessageBox.Show("Youe Data Successfullly Added");
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
