How to undo changes of framework change? - c#

Recently, I've been working on a project with Access database, but since the deployment would be on a XP computer, I tried changing the .NET Framework from 4.5.1 to 4.
Since then the connection fails to open, and continues to fail even tough I changed it back to 4.5.1.
con.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source = " + Localexe + #"/Database.accdb";
try
{
con.Open();
}
catch (Exception x)
{
}
It says that:
provider 'Microsoft.ACE.OLEDB.12.0' could not be found on the local
machine
I tried opening a new project and seeing if there were any References that got lost on the process but that didn't seem to work.

What is your OS and its bit? what is your access bit? x86 or x64?
anyway pls try :
DefaultAppPool and Classic .NET AppPool (find these path) - right click - 32bit app enable(true)...after this , right click and restart.
I guess it works.

Related

Compact and repair Access DataBase in run time using C# without Access installed

I write a program that should run on a lot of machines
I did not installed Access in the machines But I have an access database using on them
When I write and delete data from this Access databases its size grow up so every few days I have to compacts them and to shrink the size
This is the code I using
public void Compacting()
{
try
{
Microsoft.Office.Interop.Access.Application application = new Microsoft.Office.Interop.Access.Application();
string dbName = "";
try
{
dbName = ConfigurationManager.ConnectionStrings["LocalPulserDB"].ConnectionString.Split("Data Source=").Last().Split(";").First();
}
catch (Exception ex)
{
string localDbError = "DataBase location is incorrect ";
System.Windows.MessageBox.Show(localDbError);
Environment.Exit(1);
}
CompactAndRepair(dbName, application);
}
catch (Exception ex)
{
try
{
LocalPulserDBManagerInstance.WriteLog(ex.StackTrace, ex.Message);
}
catch (Exception)
{
}
}
}
private void CompactAndRepair(string accessFile, Microsoft.Office.Interop.Access.Application app)
{
string tempFile = Path.Combine(Path.GetDirectoryName(accessFile),
Path.GetRandomFileName() + Path.GetExtension(accessFile));
app.CompactRepair(accessFile, tempFile, true);
app.Visible = false;
FileInfo temp = new FileInfo(tempFile);
temp.CopyTo(accessFile, true);
temp.Delete();
}
But I got the next error :
{"Retrieving the COM class factory for component with CLSID {73A4C9C1-D68D-11D0-98BF-00A0C90DC8D9} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))."}
What can I do?
Interop requires Office to be installed on the machine the code is running on, I suspect you won't be able to utilize that method for performing the compact and repair.
https://social.msdn.microsoft.com/Forums/en-US/973ce94f-5235-4be9-a2b1-51ba7d35e1f3/installing-office-primary-interop-assemblies-without-actually-installing-office?forum=innovateonoffice
You may however be able to utilize this standalone tool, "Jet compact utility":
https://learn.microsoft.com/en-us/office/troubleshoot/access/jet-compact-utility-download
You do not need nor even want to create a whole instance of access to just compact. (or even use + pull data from the tables.
Set a reference to the ACE database engine. That way you can pull + use data, and not have to automatic (create) a rather heavy application object like Access. And if you do create a WHOLE instance of Access, then things like VBA code and startup forms run (not only is a that bad since now you have a hidden UI - but you can't answer prompts, and worse that startup code may will have launched a form which in term will open a table, and then you can't compact until such time all tables are closed.
IN vb.net code, this will compact:
Dim ACEEngine As New Microsoft.Office.Interop.Access.Dao.DBEngine
Dim strDatabase As String = "c:\test\test44.accdb"
' you always compact to a copy - you cannot compact "over" the existing database
Dim strTempDB As String = "c:\test\temp.accdb"
Debug.Print("starting compact")
Try
ACEEngine.CompactDatabase(strDatabase, strTempDB)
Debug.Print("compact done")
Catch ex As Exception
Debug.Print(Err.Description)
End Try
Note that:
You can check the error code as per above, since if ANY other users are in the database, then the compact will NOT occur.
The above output if a someone else has the database open?
starting compact
Exception thrown: 'System.Runtime.InteropServices.COMException' in ACETest.exe
You attempted to open a database that is already opened by user 'Admin' on machine
'ALBERTKALLAL-PC'. Try again when the database is available.
So, catch the error. As above shows, you need a interop reference to
C:\Program Files (x86)\Microsoft Visual Studio 12.0\
Visual Studio Tools for Office\PIA\Office14\
Microsoft.Office.interop.access.dao.dll
Just check that err.Number is 0. If the compact occurred, then you can delete or better yet rename the original database, and then rename the "temp" database back to the original name. (A compact + repair from the Access UI does this behind the scenes and actually never overwrites the original file during the compact process as it might fail or not work). You could attempt to check for existing .ldb file (a lock file) before you attempt the compact, but the compact process checks + requires that you have 100% exclusive use of the file, and if the compact can't get exclusive use of the file, then a error message is spit out as per above.
So, just add the assembly reference to your project. You should also force your .net project to x86, and not leave it to "ANY CPU".
the above will work WITHOUT Access having been installed. However, you will need to have the JET or ACE data engine installed. The JET engine is installed on all copies of windows by default - but will ONLY work with mdb files. If you need to compact and use a accDB file, then you will have to install the ACE database engine - but it is a FAR smaller footprint and install then is a whole copy of Access or the run time (both are about the same size and are quite large. As noted, with above, then you don't require Access to have been installed on the computer.
Edit
You can find + install a version of ACE from here:
https://www.microsoft.com/en-us/download/details.aspx?id=54920
Note in above, you are given two choices. (x32 or x64 - so you have to install the version you want. This also suggests you need two versions of your .net code OR YOU CAN find a shortcut way to launch "any" cpu to start as x32 or x64 - HOW you start your .net project will determine if it is running as x32 or x64 if you going to choose "any cpu" as opposed to forcing the .net project (and providing two versions of the project as I have done in the sample link below).
I have a working .net (tiny) .exe file from here that lets you run as x32, or x64, and thus you can quick check which version of ACE you have installed.
link:
https://onedrive.live.com/embed?cid=B18A57CB5F6AF0FA&resid=B18A57CB5F6AF0FA%21101313&authkey=AB-I3mHVZhLmd2Q

Application crashes on debugging a web project with exit code -2147023895 (0x800703e9) in Visual Studio 2017

I am trying to debug a web api project on a newly setup laptop with Visual studio 2017 professional edition.
It uses Target framework of .NET Framework 4.6.1.
The web application (not visual studio) crashes few seconds after starting with this in the output window.
The program '[4868] iisexpress.exe' has exited with code -2147023895 (0x800703e9).
And for every crash, I see this message in Event Viewer
The description for Event ID 0 from source VSTTExecution cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
(devenv.exe, PID 24968, Thread 1) IdleProcessorManager.DoWork - Job threw:
Invalid URI: The format of the URI could not be determined. at
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at Microsoft.VisualStudio.TestTools.TestCaseManagement.SolutionIntegrationManager.IsRunConfig(String filename)
at Microsoft.VisualStudio.TestTools.TestCaseManagement.SolutionIntegrationManager.d__351.MoveNext()
at Microsoft.VisualStudio.TestTools.TestCaseManagement.IdleProcessorManager.DoWork()
The message resource is present but the message was not found in the message table
I already tried deleting .vs folder, restarting pc, uninstall/install vs, uninstall/install .net framework amongst other things.
Can someone help me fix this, unable to get to the 'real' reason for these failures.
Things to note -
1. The project works fine on other machines.
2. I can create a new project using project template and run/debug application successfully.
EDIT : On more investigation I find that the web application breaks (without any error other than the exit code) and exits.
public virtual DataSet Execute(SqlCommand sqlCommand, SqlConnection sqlConnection)
{
if (sqlCommand == null || sqlConnection == null)
{
return null;
}
var ds = new DataSet();
if (sqlConnection.State != ConnectionState.Open)
{
sqlConnection.Open();
}
using (var adp = new SqlDataAdapter(sqlCommand))
{
adp.Fill(ds); <---- BREAKS here!
return ds;
}
}
On another machine where its working, it works perfectly fine. And the SP returns around 390K records. Possible stackoverflow exception?
Please check the Framework versions that are installed to your new laptop.
I suspect that the minor versions don't match wiht your new laptop.
You can check which versions are installed to your machine via the link:
https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
Edit:
1- Install the version from :
https://www.microsoft.com/en-us/download/details.aspx?id=49981
2- Or I recommend you to upgrade your Project's framework to .NET Framework 4.7.2

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.

Running in 64 bit mode with the 32 bit Oracle Service

This question similar to link
link2
I fixed this problem, but when I opened new project Wcf service library, I had that same problem, and all this changes that I had done before did't help me.
I tried every thing that I did before and even more but it didn't helped.
It is important to say that if I do the same in another project all work fine but in WcfServiceLibrary it doesn't work.In WcfServiceApplication it working too.
I use VS2012(4.5) Win7 (64), my Oracle clien 32, but in other project this is not a problem.
Maybe it because Wcf library project i don't know.
i just buil service that save datd from database and i get error on connection to db.
Error: Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
My code
using (OracleConnection con = new OracleConnection())
{
con.ConnectionString = "User Id=zxc;Password=zxc;Data Source=NXE";
con.Open();//here i get error
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText = "select * from " + Table;
int rowsUpdated = cmd.ExecuteNonQuery();
OracleDataReader reader = cmd.ExecuteReader();
String DataFromORL = "";
int row = 0;
while (reader.Read() && row < 50)
{
row++;
if (reader.HasRows)
{
DataFromORL += reader.GetInt32(0);
}
}
}
I too got the same issue.
for me issue got fixed by doing the following thing.
prior to this check whether you have installed both 32bit and 64bit Oracle clients to make it available in both environments.
for me the reason for getting this error.
Error: Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64-bit mode with the 32-bit Oracle client components installed.
is because of the environmental variables has only one installation location and it is 32bit installation location that's why the error is This problem will occur when running in 64-bit mode with the 32-bit Oracle client components installed.
so, to resolve this what I did is, I added 64-bit installation location also and restarted my visual studio. if it does not work try by restarting system also, we are supposed to add both bin directories available in Oracle client installation location that we specify while installing Oracle clients. In my system location is like: 32-bit C:\app\client\<user>\product\12.1.0\client_2\bin
64-bit C:\app\client\<user>\product\12.1.0\client_1\bin

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