No solution for 'Microsoft.ACE.OLEDB.12.0' error - c#

I have a problem with an MVC C# application in one controller.
The following code continues to give the error:
*The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.*
The code below:
var excel = new ExcelQueryFactory("~/App_Data/uploads/" + tempName);
var usersForImport = from c in excel.Worksheet<User>()
select c;
int count = usersForImport.Count();
for (int i = 0; i < count; i++)
{
User user = new User();
user = usersForImport.Skip(i).First();
db.Users.Add(user);
db.SaveChanges();
}
I have tried 2 solutions from previous posts, as I thought this problem was identical, but they do not solve the problem.
The two solutions I have tried are to install the Microsoft Access Database Engine or set the target platform for x86.
The code relies on 'linqtoexcel' package.
Has anyone else run into these problems? Any solutions?

For 64-bit apps, there are two versions of the ACE driver available:
http://www.microsoft.com/en-us/download/details.aspx?id=23734 for Office 2007
http://www.microsoft.com/en-us/download/details.aspx?id=13255 for Office 2010
I believe the Office 2007 version has the ProgId 'Microsoft.ACE.OLEDB.12.0', so I would try this one rather than Office 2010, which I believe has the ProgId 'Microsoft.ACE.OLEDB.14.0'.
From your description, it looks like the linqtoexcel package might depend on the Office 2007 version.

I have solved this in properties of the project, in the Build Tab.
I have changed the platform target from x64 to x86

Related

Microsoft.Office.Interop.Excel.Application - Invokeing Different Versions of Excel

I have the following issue:
var oExcelApp = new Microsoft.Office.Interop.Excel.Application();
On this machine this starts Excel 2016, however I have both Excel 2010 and Excel 2016 installed on my machine. I'd like to start 2010 instead, and I'd like to keep both 2010 and 2016 installed on my machine when I do that.
According to this post, it's not possible. However, my understanding is that you can do this programmatically using the following commands:
(To register Excel 2010 as the default application)
"C:\Program Files (x86)\Microsoft Office\Office14\Excel.exe" /regserver
However when I run this command, all it does is open excel, the desired effect is not observed. Is there a way to do this, maybe with some sort of registry change? Or referencing a different version of libraries?
Update 1
I've tried this too:
var oExcelApp = (Microsoft.Office.Interop.Excel.Application)Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application.14"));
Doesn't seems to work either, disregards the excel version and runs 2016 irregardless of the specified version.
This seems to work quite well. Not sure what the difference between "_Application" and "Application" is, but per the comment "Application" is preferred:
string pathToTheVersionOfExcel "...";
int amountOfTimeToWaitForFailure = 5000;
Process process = new Process();
process.StartInfo.FileName = pathToTheVersionOfExcel;
process.Start();
Thread.Sleep(amountOfTimeToWaitForFailure);
oExcelApp = (Application)Marshal.GetActiveObject("Excel.Application");

ML.NET: strange runtime error on some machines

I wrote a simple UWP app using the ML.NET framework, and it worked on one of my machines without installing any Nuget packages, without any additional setup etc.
However, on my other machine, after running the application, I get this error:
System.Runtime.InteropServices.COMException: 'Unspecified error
No suitable kernel definition found for op Sub (node Minus675)'
The error happens in this segment of code:
public static async Task<modelModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
{
modelModel learningModel = new modelModel();
learningModel.model = await LearningModel.LoadFromStreamAsync(stream);
learningModel.session = new LearningModelSession(learningModel.model); // it breaks here
learningModel.binding = new LearningModelBinding(learningModel.session);
return learningModel;
}
In case anyone should ask - yes I have added my .onnx model in the Assets folder. My configuration is: VS 2017, Windows 10 version 1809, build 17763.194, and I have Windows 10 SDK version 10.0.17763.132. I have tried installing the Visual Studio Tools for AI and ML.NET Templates VS extensions, but it didn't help.

PPTX to Image conversion doesn't work on windows server 2012 production

We have requirement to convert uploaded PPT or PPTX files into image files. We developed this working locally with following (POC code):
Application pptApplication = new Application();
Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApplication.Presentations.Open2007(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
List<string> files = new List<string>();
for (int i = 1; i <= pptPresentation.Slides.Count; i++)
{
pptPresentation.SaveCopyAs(serverPath + randomId, PpSaveAsFileType.ppSaveAsPNG, MsoTriState.msoTrue);
files.Add(root + "Uploads/Slide" + i + ".PNG");
}
pptPresentation.Close();
Now when this code is deployed on Windows Server 2012 R2, I receive following error:
This error looks like some access permissions issue and when I googled I found several solutions which I tried with no luck, here's some of them:
Install office on server - not make any sense to have office on server :( well I installed and still getting same issue.
Install office Interop Assemblies on server - i can't find this assembly for windows server 2012, the one i found here https://www.microsoft.com/en-us/download/details.aspx?id=3508 is not supported for 2012 and when I installed it doesn't work.
Tried this solution https://stackoverflow.com/a/30117146 as well
We can't switch to paid solutions like Aspose, Spire etc
Any help on this thread is highly appreciated.
Thanks.
Here's the narrowed down solution which worked on all the servers, i'm posting this solution after 7 months mature research.
Installed Office and activated the product on every servers
Created a folder 'Desktop' at C:\Windows\SysWOW64\config\systemprofile\Desktop (64 bit OS)
In IIS changed ApplicationPool identity from 'ApplicationPoolIdentity' to 'LocalSystem'.
That's it and i was able to convert slides into images.
Source Code
In case you are interested in code that I was using:
Application pptApplication = new Application();
Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApplication.Presentations.Open2007(Server.MapPath("~/tempslides/pptfilename.pptx"), MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
List<string> files = new List<string>();
for (int i = 1; i <= pptPresentation.Slides.Count; i++)
{
pptPresentation.SaveCopyAs(serverPath + randomId, PpSaveAsFileType.ppSaveAsPNG, MsoTriState.msoTrue);
files.Add(Server.MapPath("~/tempslides") + "/slide" + i + ".PNG");
}
pptPresentation.Close();
To run above code, you need to add reference to interop lib in your project.
Hope this helps you to save your time.

Error HRESULT E_FAIL has been returned from a call to a COM component while opening a powerpoint document using C#

Trying to cope up with HRESULT E_FAIL error that I keep getting while trying to open a powerpoint file. There is more to code but the very basic operation for which I get the error is shown in the code block below. Reference DLLs being used are: Office 14.0.0 and Microsoft.Office.Interop.Powerpoint 14.0.0.
Application application = new Application { DisplayAlerts = PpAlertLevel.ppAlertsNone };
Presentation powerpoint = application.Presentations.Open(#"X:\XXX\xxx.pptx");
powerpoint.SaveAs(#"X:\XXX\saved.pdf", PpSaveAsFileType.ppSaveAsPDF, MsoTriState.msoTrue);
It's a very basic operation, but not sure why it's complaining about the COM Exception.
Microsoft Office 2010 32-bit with Service Pack 1 is installed on the machine.
I had the same exact problem. I have searched for the solution for a few day.
At last I found it.
When you install MS Office 2010, you should install "Office Shared Features" with Powerpoint in Office CD together.
After installing "Office Shared Features", everything is OK.
Powerpoint needs to be visible before it can open a presentation. Right after creating the new Application object call this:
application.Visible = MsoTriState.msoTrue;
If this still doesn't resolve the exception you'll have to post more details about the exception. Somewhere in it's properties (or maybe inner exceptions) it should say what exactly failed.

Oracle.DataAccess Error

I have an asp.net / C# web application running in a Windows environment.
The project builds fine and runs perfectly on my local machine's VB.net development server.
However, when I publish to the real application server I receive the following error message:
[OracleException (0x80004005): The provider is not compatible with the version of Oracle client]
[TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.]
There is a version of this application currently up and running just fine, I am testing on the live server in a different directory. I even tried snagging the Oracle.DataAccess .dll from the working application but still get the same error message.
First off: The Oracle client/provider is a mess. And that goes for both the MS one (depreciated anyway) as well as the Oracle one.
In order to connect to an Oracle DB via the ODP.NET provider three things need to be setup properly:
Oracle client needs to be setup properly ( has nothing to do with the .NET provider, this referring to the installed oracle client usually in c:\oracle)
The ODP.NET provider needs to be compatible with the installed Oracle client
The architecture of client and provider and your application need to match, you cannot use the 64bit client with an x86 provider/application and vise versa
Usually the best is to have the newest version of both. But if you want to get rid of this issue once and for all use a third party oracle .NET provider.
UPDATE
One of the better ones is from DataDirect (no affiliation):
http://www.datadirect.com/products/net/net-for-oracle/index.html
It's not just installation (no oracle client necessary), but it's also faster, fully managed, x64 and general support is a way better than what you get with the ODP.NET one. It will cost you though.
The DevArt one is pretty decent as well (and much much cheaper):
http://www.devart.com/dotconnect/oracle/
We decided for the DataDirect for extensibility reasons, this should not be relevant to you however.
Here you can find a good compilation of third parties that build .NET providers, not limited to oracle though:
http://msdn.microsoft.com/en-us/data/dd363565
I came across the same scenario before
Reading this may help you some how ODAC Oracle for .NET
about your problem in your server you have to install the whole ODAC Client from oracle
the latest version now is 4.xx
i have installed it and everything works like charm
hope this helps :)
Take Care
I was able to solve this by searching for Oracle.DataAccess.dll on the prod server.
So instead of trying to build/deploy the project with the Oracle.DataAccess.dll from my development environment, I copied the .dll down from the prod server oracle client directory and included that as a reference instead. I also set the .dll properties "Copy Local = true" and "Specific Version" = true. So it looks like there is a mismatch between the oracle client version on my dev server and the prod server.
Equals, with Oracle.DataAccess.dll Works!!!!
//using Oracle.DataAccess.Client
object pdf = null;
var queryString =#"SELECT PDF FROM DIGITAL WHERE ID_DIGITAL=1001" ; //example
var ctx = new Entities();
var entityConn = ctx.Connection as EntityConnection;
if (entityConn != null)
{
var dbConn = entityConn.StoreConnection as OracleConnection;
dbConn.Open();
var cmd = new OracleCommand(queryString, dbConn);
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
pdf = reader[0];
}
}
dbConn.Close();
}
return pdf;
In addition to the other suggestions, just try running Visual Studio as administrator.
I spent a lot of time messing around with the GAC and various versions of the Oracle.DataAccess.dll, and in the end just running VS as administrator got it to run.

Categories

Resources