Visual Studio Project Installer not installing all dll's - c#

I have a C# exe, called 'start.exe' that is when run will check a SQL database and copy a file to a folder if certain criteria are met.
This works on most computers.
But on some computers when I try to run it I get the following error message.
System.invalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' is not registered on the local machine
To fix this I created a setup project that should add the missing .dll.
I created the set up project, went to the applications folder, added the primary output of the project.
I then ran a batch build on all the files and copied the msi and setup .exe files to a problem computer and ran it.
It adds System.Net.Http.dll and 'start.exe' to the computer.
When I run the exe, it still gives me the same error.
I believe the message box comes from these lines of code.
try
{
using (var conn = new OleDbConnection(#"Provider =Microsoft.ACE.OLEDB.12.0;Data Source=" + CurFeSource + ";"))
{
conn.Open();
using (var cmdBE = new OleDbCommand("SELECT value FROM Tab1", conn))
{
OleDbDataReader rdrBE = cmdBE.ExecuteReader();
rdrBE.Read();
be_version = (rdrBE.GetString(0));
rdrBE.Close();
}
using (var cmdFE = new OleDbCommand("SELECT Col FROM Links", conn))
{
OleDbDataReader rdrFE = cmdFE.ExecuteReader();
rdrFE.Read();
fe_version = (rdrFE.GetString(0));
rdrFE.Close();
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
return false;
}
Edit:
As SQLGeorge said, I need to install Microsoft.ACE.OLEDB.12.0.
But how do I add it to a setup project.

The Microsoft.ACE.OLEDB.12.0 must be downloaded from Microsoft:
https://www.microsoft.com/en-US/download/details.aspx?id=13255
Excerpt From Microsoft:
This download will install a set of components that facilitate the transfer of data between existing Microsoft Office files such as Microsoft Office Access 2010 (*.mdb and .accdb) files and Microsoft Office Excel 2010 (.xls, *.xlsx, and *.xlsb) files to other data sources such as Microsoft SQL Server. Connectivity to existing text files is also supported. ODBC and OLEDB drivers are installed for application developers to use in developing their applications with connectivity to Office file formats.
As noted by Microsoft:
As a general replacement for Jet (If you need a general replacement for Jet you should use SQL Server Express Edition).

Related

How to import old mdb-database into C# DataTable [duplicate]

This question already has answers here:
Proper way of getting a data from an Access Database
(4 answers)
Closed 1 year ago.
I got a very old mdb-database.
I want to load all tables from the database into a C# DataTable.
If possible the final tool should be stand-alone and don't need to install additional software.
Environment
.NET 5.0
Visual Studio 2019
Windows 10 - 64 bit
Office 365 - 32 bit
Questions:
How does the code for this looks like?
Which packages do I have to add/install?
Are there other dependencies?
Code:
string dbLocation = "DatabaseName.mdb";
string tableName = "TableName";
string connString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={dbLocation}";
DataTable results = new DataTable();
using (OleDbConnection conn = new OleDbConnection(connString))
{
OleDbCommand cmd = new OleDbCommand($"SELECT * FROM {tableName}", conn);
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(results);
}
Conditions:
In order to the Office-Version that is installed (32/64 bit) you have to install Microsoft Access Database Engine 2010/2016 Redistributable (for me it was 2010).
Most office installations are 32 bit.
Microsoft Access Database Engine 2010 Redistributable
Microsoft Access Database Engine 2016 Redistributable
If you choose the right version an still get an error trying to install in silent mode
accessdatabaseengine.exe /quiet
Add package System.Data.OleDb
Target plattform of the application has to be set to x86/x64 according to the other packages that are used
Still not solved:
Actually you need to have Microsoft Access Database Engine Redistributable installed. If there exist any other methode without this, please let me know.

Excel upload not working on windows Server 2012

I have developed an application where the user have to upload a winzip archive file. The code then extracts an Excel file (in .xls format, 97-2003 workbook) from that archive and uploads the data within that Excel file into my SQL database table. I'm using ZipFile.ExtractToDirectory(zipPath, extractPath) to extract the file.
Below is the code I'm using for the excel upload.
using (OleDbConnection connExcel = new OleDbConnection(Excelconstring))
{
using (OleDbCommand cmdExcel = new OleDbCommand())
{
using (OleDbDataAdapter odaExcel = new OleDbDataAdapter())
{
cmdExcel.Connection = connExcel;
connExcel.Open();
DataTable dtExcelSchema;
string sheetName = "Chat Summary$";
//DateTime.Today.ToString("M.d.y$");
// Read Data from First Sheet.
cmdExcel.CommandText = "SELECT * From [" + sheetName + "]";
odaExcel.SelectCommand = cmdExcel;
odaExcel.Fill(dt);
connExcel.Close();
}
}
}
The problem is this works absolutely fine on my local system 64-bit Windows 7 with Microsoft Office 2010. I'm using Microsoft.Jet.OLEDB.4.0 on my local system. The problem is when I deploy the same code on my server (Windows Server 2012 with Microsoft Office 2013), this doesn't work. I have installed Microsoft Access 2010 redistributable on the server and change the provider to Microsoft.ACE.OLEDB.12.0 but still it doesn't work. The error I get after changing the provider to ACE is
External table is not in the expected format
Also when I extract the file myself, open it once and then archive it again - it works fine. I have tried many solutions from different forums but none of them seems to work. I have changed the debug mode from "anycpu" to "x86" and "x64" but still it doesn't work.
The steps I have already tried are installing the Microsoft Access 2010 redistributable, changing the debug mode from "anycpu" to "x86", changing the connection string from Jet.OLEDB.4.0 to ACE.OLEDB.12.0.
Excel 2010 is still a 32-bit application. Therefore, try setting Enable 32-bit applications to True on your IIS App Pool.

Data source name not found and no default driver specified when reading mdb file in 64 bits OS from 64 bits app:

I have a ASP.NET MVC application (64bits) running in a 64 bits Windows system (Windows Server 2012).
My web application needs to read a mdb database, then I created the next code:
using (var myConnection = new OdbcConnection())
{
try
{
string myConnectionString = #"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + fileNameWithPath + ";Persist Security Info=True";
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
OdbcCommand cmd = myConnection.CreateCommand();
cmd.CommandText = "SELECT * FROM myTable";
OdbcDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
// Load the result into a DataTable
myDataTable = new DataTable();
myDataTable.Load(reader);
}
catch (Exception exception)
{
//nexy exception is caught here: "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
}
finally
{
myConnection.Close();
}
}
Where fileNameWithPath is the path of the mdb file.
When I execute the code above, I have the next annoying exception in the line
myConnection.Open();:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not
found and no default driver specified
I've checked the server and it has the next files installed regarding ODBC driver:
File odbcad32.exe under the folder C:\Windows\System32
File odbcad32.exe under the folder C:\Windows\SysWOW64
My question is: Is my server setup correct? Do I have the 64 bits version of ODBC really installed?
and more important: Can I run a x64 application in x64 server with such configuration? Otherwise, is there any other alternative? It is worth to mention that:
I'm not allowed to install additional software in the server
The web application must be 64 bits
Thanks in advance.
To use the x32 bit version of the Access database engine, then you will require an x32 bit version of the database engine installed on that computer.
And to use the x64 bit version of the Access database engine, then you require an x64 bit version of the Access database engine to be installed.
And hey, if you need to read an oracle database, then lo and behold, you need the oracle database engine installed to read oracle files that reside on the disk drive.
If you can’t install any additional software such as oracle to read oracle files, or SQL server to read sql server files, or in this case Access, then you are duck soap. And really, to read PDF files, then you need some PDF file software installed.
So unless you can get around the issue of not being allowed to install the appropriate software on your server, then you not going to be able to read the given files that such software consumes – this applies to near EVERY software system - you need to install the appropriate software on that server to enable use of such files.
So there does exist both an x32 and x64 bit version of the Access database engine (ACE), and unless you are allowed to install such software then you can’t read and consume such data.
So keep in mind that when developing software, if you want to open a word file, or pdf file or like any software system you will require the apocopate software to be installed to work with such files – Access is no exception. If you need to open a power point file, then it becomes obvious that you need power point software installed on that computer.
So you need to obtain and install the x64 bit version of the Access database engine on that server. And since you note you can’t install any software, then you are unlikely to achieve your goal.
I resolved a very similar issue by enabling 32-bit applications in the advance settings of the application pool in IIS

OleDbConnection.Open() throws exception only in one project, same code works in other projects

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
I know the common fix for this which is to install:
Microsoft Access Database Engine 2010 Redistributable
Or
2007 Office System Driver: Data Connectivity Components
Both are installed on my local PC. This is the code which I have
OleDbConnection conn = new OleDbConnection();
string fileName = "test.xlsx";
try
{
string connectString = String.Format(
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR={1};'",
fileName, "YES");
conn.ConnectionString = connectString;
conn.Open(); //exception is thrown here !!!
OleDbCommand comm = new OleDbCommand();
comm.CommandText =
string.Format("CREATE TABLE [{0}] ", "Test");
comm.Connection = conn;
comm.ExecuteNonQuery();
OleDbDataAdapter ad = new OleDbDataAdapter(
string.Format("SELECT * FROM [{0}]", "Test"), conn);
OleDbCommandBuilder builder = new OleDbCommandBuilder(ad);
}
catch(Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
I try this code in other projects on my local machine and everything is working. I have project which creates excel exports and I don't have this problem.
The problem is in the project I don't understand how to fix it. Also on the current project I create one new .aspx page and in Page_Load put only this code, same exception.
Additional information: this project was written on vs 2008, convert to 2010 and after that used in vs 2012. Everything was working in the project till now.
Also same thing for JET connection string !
EDIT
After the answer of Joe I see that this project is run on 64bitProcess:
bool test = Environment.Is64BitProcess; //return true.
My driver is for 32bit. What I can do now, can I change the environment process. I can't install the driver for 64bit process because I have installed Office 2010 x32.
The OLEDB drivers for 32-bit and 64-bit applications are different.
If you only have the 32-bit driver installed, then 64-bit applications that attempt to use it will get this error. Similarly, if you have only the 64-bit version installed, then 32-bit applications that attempt to use it will get this error.
You say:
I try this code in other projects on my local machine and everything is working
Ergo, at least one of the two must be correctly installed.
To understand what's happening you could examine Environment.Is64BitProcess in both the application that works, and the one that doesn't. That will tell you which version is missing.
Then download and install the 32-bit or 64-bit version that's missing from:
http://www.microsoft.com/en-us/download/details.aspx?id=13255
You need AccessDatabaseEngine.exe (32-bit) or AccessDatabaseEngine_64.exe (64-bit)
Note that you may need to specify the provider as 'Microsoft.ACE.OLEDB.14.0' for the Office 2010 version (12.0 was for Office 2007).
After some hours I found a solution:
What were the steps, first I try to run the project on x86 - Properties/Build/Platform Target. Exception was thrown that I can't rebuild, because a registry was false. I create the registry. How to do it:
In notepad file paste this code and save it like reg file. Make the file name something to remember why you have it in the future(Fusion.reg).
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
"EnableLog"=dword:00000001
After that I had a problem because not all of my assemblies was readable by the application pool. Solution about that was going to IIS/Application Pools/Application Pool 4.0/General/Enable 32- Bit Applications. After that restart the IIS, close the project and open it again and everything was working with 32bit version.

First Step into ADOMD.Net - Cannot reference Microsoft.AnalysisServices

Can someone help me out please, as google is not providing the answers.
I've got a SharePoint 2007 setup which uses SQL Server 2008 R2 SSAS OLAP cubes via some web parts.
As a C# developer, Sharepoint is a nightmare, so I decided I needed to try to get to grips with just C# and OLAP interaction. My cubes all exist, and are working, so all I needed to do was create a simple C# App to get it all straight in my mind.
I've downloaded Microsoft.AnalysisServices v10.0.0.0 and I can see it sitting happily in my GAC, but I can't add a reference from within my Visual Studio 2010 C# 4.0 project. It's just notappearing. I've tried setting the app to use 3.5, but still no joy.
Any clues?
Have you added the reference for Microsoft.AnalysisServices.AdomdClient.dll located in C:\Program Files\Microsoft.NET\ADOMD.NET\100
You could also use the nuget package manager. Type this in the console
Deprecated version (does not exist anymore):
install-package Microsoft.AnalysisServices.AdomdClient
New version:
Install-Package Microsoft.AnalysisServices.AdomdClient.retail.amd64
I think you need to reference the file directly, rather than through the GAC. It should be located in C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies
AdomdConnection steps
AdomdConnection con = new AdomdConnection("connectionstring"); // connect DB
con.Open();
AdomdCommand cmd = new AdomdCommand("MDX query", con); //query
AdomdDataReader reader = cmd.ExecuteReader(); //Execute query
while (reader.Read()) // read
{
Data dt = new Data(); // custom class
dt.Gender = reader[0].ToString();
dt.Eid = reader[1].ToString();
dt.salary = reader[2].ToString();
data.Add(dt);
}

Categories

Resources