Unlocking SQL Compact (.SDF) file when data entry form closes - vb.net

I have developed a small Stock-Take application that runs on a Windows Mobile 6.5 handheld device & uses a SQL Compact 3.5 (.SDF) data file. I built the application in Visual Studio 2008 using VB.Net and it all works fine up to the point where I need to copy the data file back to the connected PC for further processing. When I close the application data entry form, the data file remains locked and I can't copy it to the PC. In the Form_Closed event, I am issuing Dispose commands for both the TableAdapter and BindingSource, and have also added a Garbage Collect command, see code below, but the data file remains locked.
Private Sub StockCheckForm_Closed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed
Me.StockCheckTableAdapter.Dispose()
Me.StockCheckBindingSource.Dispose()
GC.Collect()
MsgBox("Form Closed", , "Stock Check")
End Sub

Related

Create folder in Windows CE

I am working on an old application running on a Windows CE device. This is old software that is still in use.
As of now, they need to create the folder on the flash drive (there are no drive letters). My idea was to create the folder if missing. However, it gives an error when creating the directory.
The folder is used to save data for later use.
Any ideas on how create a folder from SW?
Here is my VB code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Directory.Exists("QuaData") Then
Directory.CreateDirectory("QuaData")
End If

Handle Application closing event without Dispose event handler

I'd like to know if there is a possible way to handle a closing application in Visual Studio 2008 without using the dispose event handler.
If my application crashes or if I close it while it is running:
Private Sub Foo_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
Is not called.
This result in a serious problem, because I'm currently working on multiple Excel files and they remain open after the application crashes or I close it while it's running.
Is there a way to handle this kind of closing application event?
In a normal situation when your application is simply closing you can subscribe to the MyApplication.Shutdown event and close your excel documents in there.
Subscribing to the event can be done through these steps:
Right-click your project in the Solution Explorer and press Properties.
Go to the Application pane and press View Application Events.
In the file that was opened, either write the event handler on your own or let VS do it by first selecting (MyApplication Events) in the left combo box above the text editor, then selecting Shutdown in the right combo box.
Now you should have an event handler that looks something like the one below. Just go ahead and do your cleanup in there:
Private Sub MyApplication_Shutdown(sender As Object, e As System.EventArgs) Handles Me.Shutdown
'Do your cleanup here...
End Sub
For application crashes caused by CLR exceptions you can use the AppDomain.UnhandledException event, but for more serious crashes there isn't very much you can do.
A workaround would be to create another application which monitors your main app. When the other app senses that your main application's process has been terminated, it will close the excel documents. The tricky part with this solution is passing the information necessary for the other app to close the documents.

Closing main form doesn't finish process (only some computers)

The problem is happening on 2 of the company's computers and on a client computer, but we can not identify a pattern.
I was able to reproduce the error using a simple program that only opens an OpenFileDialog. The program must be run by the generated executable itself (NOT by Debug) and it is still running in the background even after closing. Below is the code of the program, along with a link to download the project and a video demonstrating the error.
Code:
Public Class Form1
Private ofdAbrir As Windows.Forms.OpenFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ofdAbrir = New Windows.Forms.OpenFileDialog
ofdAbrir.ShowDialog()
ofdAbrir.Dispose()
ofdAbrir = Nothing
End Sub
End Class
As you can see in the code above, I only have one form, so it is not the case that some form remains open and it is also not related to threads running since none is created.
To reproduce the problem, click on Button1, cancel the OpenFileDialog and try to close the form (clicking on X). The form apparently will close, but you will see at task manager that it still running. The big mystery is that this problem does not happens in all computers.
Video: https://drive.google.com/open?id=1sfdVUGQlwYNCQkl1Ht-cJSOb4433sqnT
Project: https://drive.google.com/open?id=1d4oJYUjaaZ9xnRj4CX3HXOQPqwMZmE0V
I couldn't reproduce the problem, but how about using this method:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Using ofdAbrir As New Windows.Forms.OpenFileDialog
ofdAbrir.ShowDialog()
MsgBox(ofdAbrir.FileName)
End Using
End Sub
I've seen the video u posted...It is not your application that is running rather it is the vsHost.exe that is running :)...The problem shouldn't occur if u run the app outside visual studio.
If the problem is still there,just disable Enable Diagnostic Tools while debugging from Tools > Options > Debugging > Uncheck Enable Diagnostic Tools while debugging
Also u can disable Visual Studio hosting service from Project > Project Properties > Uncheck Enable the Visual Studio hosting service

Get focus back when clicked outside the form

I wrote a program to controle the audio volume by a remote control.
It needs to keep focused, otherwise it does not receive its commands anymore.
In order to get the focus back a used a timer, checking every second if the form still has the focus.
Here is the code:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Not Me.Focused Then
Me.Activate()
End If
End Sub
As long as I run it from within Visual Studio this works perfect.
When I close Visual Studio it does not take the focus back anymore.
I ran the program on another computer on which was no Visual Studio installed and it works!
What could be the problem?

Datagrid not loading the form

Here is the screenshot of it
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CustomerRecordsDataSet.CustomerRecords' table. You can move, or remove it, as needed.
Me.CustomerRecordsTableAdapter.Fill(Me.CustomerRecordsDataSet.CustomerRecords)
End Sub
First of all I'm just a newbie with VB. I tried searching for tuts and tried to use the datagrid. I created my MS Access document for the database and created the form so I linked the datagrid form to my main window but whenever I click the button for the datagrid form it shows InvalidOperationException was unhandled and it highlights this Me.CustomerRecordsTableAdapter.Fill(Me.CustomerRecordsDataSet.CustomerRecords).
Need an ASAP explanation thanks in-advance
The error is telling you what the problem is. The data provider isn't there (Microsoft.JET.OLEDB.4.0). This can happen if you don't have it installed, or you are running an "Any CPU" or "x64" application on a x64 system. Have you tried the ACE provider (Microsoft.ACE.OLEDB.12.0)?
Details: https://www.connectionstrings.com/access/
There are also many articles on that site that address various problems. For example: Jet for Access, Excel and Txt on 64 bit systems
The Microsoft OLE DB Provider for Jet and the Jet ODBC driver are available in 32-bit versions only. You can't run them in 64 bit mode.