Quite straight forward really (well i would have thought) I am trying to create a little launcher app in C# that copies the latest version of a access database to the users C Drive and runs it. I have done everything i want except the running it part. What? would have thought that was the easy part.
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "path to the db.accdb";
proc.Start();
Now this kicks off Access ok, but when it opens Access fires an error message
"database not attached"
I have tried so many different ways and get the same result.
Further information: On my machine there are two versions of Access, 2016 (Office 16) and a Runtime version which is Office 15.
The runtime version was the most recently installed so it is what is assigned to the file type, which is the desired behaviour.
I havent tried uninstalling the runtime version to see if it works, because its the runtime version i want to use ultimately.
Any help would be greatly appreciated.
Dont worry, I am an idiot. Error message was coming from my own code in the Autoexec macro of the database.
I think i can sort it out.
Related
I recently had a new project assigned to me (I'm new to C# and I'm a junior). It makes use of a Microsoft access database file (.accdb file)
I've imported the project into Visual Studio but I can't for the life of me run the code. Initially I had file register issues, and I think I managed to resolve that by getting the IT teams to install a "2007 Office System Driver: Data Connectivity Components" driver from the Microsoft website.
Bow the error says:
System.Data.OleDb.OleDbExceptions: 'Cannot open database''. It may not be a database that your application recognizes, or the file may be corrupt.'
The team I'm trying to help only has one dev (working from a different country) who is the main person to handle the code. It works on her side, but she doesn't really have the experience to help me troubleshoot this.
I tried sending her my database file, for her to swap her file for mine, and she said it was still working, so it sounds like the issue might not be to do with the file?
Could I get any help if possible? So far my only approach is to keep googling the error.
But the only resolutions I see are from people who have database files nearing their file size limit (2GB). My database file is just 1MB.
The database file is password protected (the password happens to be in the code). I opened the database file (Microsoft access opens) and entered the password and I had no issue accessing the data)
Out of luck, I managed to find the right article to help me!
The issue with Microsoft access database files is only one user can really use then at a time I believe.
I saw a forum about potential locks made by other users. I googled how to remove locks but it seems that it might not be a lock issue (Microsoft creates a lock file which I dont have).
Regardless, I assumed that the issue is still somewhat similar. Since I had access to the database in Microsoft Access, I decided to open a new database, then go to external data tab and click on access to import EVERYTHING from the other file. Then I just renamed to old file and give my new file the original name.
I reran the code and it worked!
I dont know why the other dev had no issue opening the file. My assumption is that because she is the only developer her laptop is already 'set up' in some way to run everything as normal, whereas if someone new tried (or if something happens and she has to re-open the code on a new laptop) they would have to try and replicate the 'set up' or try and work from scratch
Hope this helps
So I have built some code, it's quite simple basically it stops all active input from keyboard and mouse until a text file of a certain name appears in the C:\Temp directory. It also has a manifest file to run it as administrator on start up.
So I found something that on the surface looks like it fulfils my needs of being able to do this task however upon running it I found out that the project has been compiled in x86 and does not run on my x64 machine. Here is the reference to the project if anyone would like to look into it, it's a very smartly designed piece of code that does an interesting objective. It also explains clearly enough what I am trying to accomplish.
So after implementing this (and failing) I have setup a couple other avenues to try, one is VBA through excel with the VBA copying itself to and from the machines in a list and running itself, then there is using VBS to write the entire code as a txt file on the target machine change the extension and then execute it remotely. I have just started researching these but I imagine the problems of running as an administrator amongst other things will crop up again to be dealt with. To be honest though I would really prefer to do this in C# only as that is the language I'm trying to go further in so I'm interested in this challenge. If anybody knows of a similar library of code or application I could look into to achieve what I'm trying I would appreciate being pointed in the right direction.
I would try and be more specific about what libraires/API's im trying to implement but the truth is I don't know what libraries I need to even interact with to get what I want. My goal is to have C# executable code on my machine and a tool that can run that executable on another machine.
Thanks
Thanks to the help in comments from #Nick.McDermaid I was able to correctly open and build the project I was trying to download. Unsure what caused the issue previously with me not being able to open and interact with the code but now I have it I shall pursue this avenue further to accomplish my goal.
As an addendum one other avenue I tried for executing code remotely was through VBS where I used
set svcproc=getobject("winmgmts:{impersonationLevel=impersonate}!\\"&MachineName & "\root\cimv2:win32_process")
scmd="""C:\Program Files\Internet Explorer\iexplore.exe"" -framemerging ""https://gifyu.com/images/Boo-Ghost-Gif.gif"""
'scmd="C:\Windows\notepad.exe"
iret=svcproc.create(scmd,null,null,pid)
set svcproc=nothing
to execute something that existed on the remote machine but I ran into a LOT of security policy issues where I could launch the process but I couldn't bring it to the foreground as the Malware tracker on the machine thought it was an attack and quashed it immediately.
I have code in a Provider-Hosted App for SharePoint which calls the OleDBDataReader class in order to parse a .xslx file. In my development environment, the following exception appeared until I installed this driver.
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. I have moved to pre-production, and the error has popped up again even though the admins of the IIS box are swearing back and forth that the driver is installed. They've sent me a screenshot of the install, and it looks like it's the same version I have. They refuse to uninstall and reinstall it since another application is apparently relying on it at the moment. Is there anything else that I can do on my end other than rewrite the code to look at some way of parsing the .xslx file using its stream instead?
I have read through many of the other topics about this, and I can't seem to find anyone doing something differently.
This thread seems to be about a similar error(granted it's for Access database), but the solution may be able to help with your problem:
In that thread the OP also installed the drivers you've linked ,that also failed so s/he installed these drivers:
http://www.microsoft.com/download/en/confirmation.aspx?id=23734
which worked apparently , try that.
I did a quick search on MSDN and the alternative download for your issue is the Office System Driver: Data Connectivity Components
The solution was for the engineering team to complete "repair" on the installation from add/remove programs.. This took forever to have them try, but it worked!
Note: While my sample code is in Powershell, I could easily convert a C# sample into Powershell. I believe that C# developers are more likely to have encountered this issue, even though I am using Powershell to try and do this.
I am trying to debug an issue with server-side Word automation. I know that you're not meant to use it for server applications and we are in the process of changing the application so it doesn't do this but until this happens I need a reliable way to debug issues where it hangs as it does so randomly.
It is not OK for me to just switch .Visible = True on the Word object because it doesn't fail all the time. I just need a way to retrieve it every now and again when it does.
If I start Word and execute this script, it works:
$w = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Word.Application")
$w.Visible = $false;
Start-Sleep -Seconds 5
$w.Visible = $true;
However, if the hanging copy of Word starts as invoked by the COM+ process, the following exception occurs:
Exception calling "GetActiveObject" with "1" argument(s): "Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))"
The Powershell and COM+ process run under the same user, and in Task Manager they both show up as running under the same user.
I have tried running Powershell as all combinations of elevated/non-elevated and x86/x64 modes to no avail.
Therefore I assume the process is in another context or area that I am not able to access from my Powershell session.
So my question is one of:
How can I launch the Powershell process as part of the COM+ process?
How can I switch my context so I can access this object instance?
Is there any other way I can try and retrieve this hidden window and set it to visible?
Unfortunately, most questions that seemed to revolve around this theme end with someone saying "well, don't do that then". Sadly we don't have an option to redevelop this significant part of the system at the moment and I would like to get this documented for those of us who have to deal with these legacy systems from time to time.
I have a set of nightly reports.
Sometimes I get the exception:
The process cannot access the file because it is being used by another process
How do I tell what process is holding on to the file? I am thinking that it is McAfee but I need to prove it.
The problem was the MailMessage in .NET was holding on to the file attachments. I had to do a dispose on the attachment and then it worked.
Use a tool like Process Explorer or Process Monitor.
Attachment data = new Attachment(#"c:\filename");
'send email....
data.Dispose();
here some tool(s) which tells and unlock locked files:
http://ccollomb.free.fr/unlocker/
Confirmed. I had a similar problem and did what Greg said.
In finally block after sending the message, I just put this in there, and it released the file handles:
foreach(Attachment a in message.Attachments) a.Dispose();
Process Explorer > Find > Find
Handle > type in your file name.
Unlocker. Try to open it, if it
has a lock, unlocker will open and
show you the programs that lock it.
GC.Collect() after the dispose should fix it
I was trying to start a Java program and got the message. Looking in Task Manager, there was already a Java task running (looping?) when I killed that process, my process was able to run.
I just had the same problem but in my case i was trying to delete a .mdf file in Visul Studio 2012. There wasn't much information on the error given to help me solve this and so i came here looking for help. Then i realized that even though its a similar problem, it was rather a different process i had to deal with.
What i did was try to delete the .mdf file in windows explorer and then i gave me an error that SQL Server 2008 R2 was in fact holding on to the file even though i had the database deleted. Once i new that, all i had to do was shutdown SQL Server 2008 R2 and tried to delete the file again and it worked.
If you need instructions on how to turn on and off SQL Server 2008 R2, see link below.
Turn on and off SQL Server
Filemon might be the tool you are looking for.
(or even Process Monitor which apparently has replaced FileMon.)