ProgressBar while taking Database bakup - vb.net

am using VB.NET as front end and PostgreSQL as backend, what i want is to create a progress bar while taking backup
code to take backup
Public Sub pgBackup(ByVal DestinationPath As String)
Dim bak As New PgSqlDump
Try
bak.Connection = Myconnstr
Myconnstr.Open()
bak.ObjectTypes = PgSqlDumpObjects.All
bak.Mode = Devart.Common.DumpMode.All
bak.Backup(DestinationPath)
Myconnstr.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "RStari9 - pgBackup")
End Try
How can i use a ProgressBar Control on bak.Backup(DestinationPath)

Related

Lucene Update not working Index Writer

I have updated a large application from .Net 4.0 to .Net 4.52 and it has broken some indexing and search functions that I have that use Lucene. I updated to the latest NuGet Packages for Lucene and I keep getting the following errors.
Type 'Lucene.Net.Index.IndexWriter' is not defined.
Type 'Lucene.Net.Documents.Document' is not defined.
Type 'IndexWriter' is not defined.
To name a few. The search functions were originally written by another developer so I am not completely familiar with it but it looks like they may have moved some namespaces when they updated Lucene to 3.0.3 but I can't find what they updated to.
Any help would be greatly appreciated!
Thanks
Code Example Below
References:
Imports Microsoft.WindowsAzure.Storage.Blob
Imports Microsoft.WindowsAzure.Storage
Imports Lucene.Net
Imports Lucene.Net.Documents
Imports Lucene.Net.Store
Imports Lucene.Net.Index
Imports Lucene.Net.Analysis
The Lucene.Net.Store says it doesn't contain any public members.
Example function that says Lucene.Net.Index.IndexWriter is not defined
Private Function IndexNewDocument(id As String, savePath As String, targetContainer As String, indexer As Lucene.Net.Index.IndexWriter, b As CloudBlockBlob) As Boolean
Dim sw As Stopwatch = Stopwatch.StartNew
Dim filename As String = ""
Dim dt As DateTime = Now
Try
' Retrieve the document and pull the metadata for reindexing
Dim docReturn As DocumentReturn = DocumentDownloadAdapter.GetDocument(_StorageEndpoint, _NewDocumentContainerName, id)
filename = docReturn.Filename
dt = docReturn.DateAdded
' Get the blob reader for indexing
Dim docReader As IBlobDocumentReader = FileProcessor.GetBlobDocumentReader(docReturn.FileBytes, docReturn.Filename, savePath)
' push the index to the blob storage database
pushIndexDocument(id, filename, dt, docReader, indexer)
sw.Stop()
OnDocumentIndexSuccessful(id, filename, sw.Elapsed)
Return True
Catch ex As EmptyPDFException
CommonCodeLib.ErrorReport("AzureStorageAccountAdapter.indexDocument", ex, "")
' DELETE FILE FROM NEW BLOB INDEX
Try
b.Delete()
Catch exDelete As Exception
CommonCodeLib.ErrorReport("AzureStorageAccountAdapter.indexDocument: Problem Deleting blob", exDelete, "")
End Try
Try
Dim username As String = getDocumentUsername(targetContainer, id)
EmailAdapter.SendExceptionEmail(ex, GetEmailList(ConfigurationHelper.IndexEmailToList), GetEmailList(ConfigurationHelper.IndexEmailCCList), username)
Catch exEmail As Exception
CommonCodeLib.ErrorReport("AzureStorageAccountAdapter.indexDocument: Problem Emailing Exception", exEmail, "")
End Try
Return False
Catch ex As InvalidDocumentTypeException
CommonCodeLib.ErrorReport("AzureStorageAccountAdapter.indexDocument", ex, "")
' DELETE FILE FROM NEW BLOB INDEX
Try
b.Delete()
Catch exDelete As Exception
CommonCodeLib.ErrorReport("AzureStorageAccountAdapter.indexDocument: Problem Deleting blob", exDelete, "")
End Try
Try
Dim username As String = getDocumentUsername(targetContainer, id)
EmailAdapter.SendExceptionEmail(ex, GetEmailList(ConfigurationHelper.IndexEmailToList), GetEmailList(ConfigurationHelper.IndexEmailCCList), username)
Catch exEmail As Exception
CommonCodeLib.ErrorReport("AzureStorageAccountAdapter.indexDocument: Problem Emailing Exception", exEmail, "")
End Try
Return False
Catch ex As Exception
CommonCodeLib.ErrorReport("AzureStorageAccountAdapter.indexDocument", ex.ToString, "")
sw.Stop()
OnDocumentIndexFailed(id, filename, sw.Elapsed, ex)
Return False
End Try
End Function

Startup Folder Permissions in VB.NET

I am building an app which installs all the company's bespoke software at the click of a button. Included in the list is an asset tracker/reporting tool which must run at startup for everyone. Our standard build (I have no control over this whatsoever) is Windows 10, and we also have some legacy Windows 7 machines around, but in each case the startup registry keys are locked down so I started to create shortcuts in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup.
If the startup folder doesn't exist, then it creates the folder. Logged on as local admin, I can create the startup folder manually without UAC popping up, take ownership of the folder and assign Everyone to have modify access, creating a shortcut in there. When I log off/on, the software runs. However when I code this, I get permissions errors.
Here's the code:
Sub DetectFolders()
Dim sFolder1 As String = "C:\My Apps\"
Dim sFolder2 As String = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\"
Dim sFolder3 As String = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\"
If Not Directory.Exists(sFolder1) Then
Directory.CreateDirectory(sFolder1)
End If
If Not Directory.Exists(sFolder2) Then
Try
' create folder
TakeOwnership(sFolder3)
Application.DoEvents()
AddDirectorySecurity(sFolder3, "MyDomain\" & Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow)
Application.DoEvents()
Directory.CreateDirectory(sFolder2)
Application.DoEvents()
TakeOwnership(sFolder2)
' everyone has modify access // TEST
AddDirectorySecurity(sFolder2, "Everyone", FileSystemRights.Modify, AccessControlType.Allow)
Catch ex As Exception
MessageBox.Show(ex.Message, "Config", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End Try
End If
End Sub
Sub TakeOwnership(ByVal sfolder As String)
' take ownership
Try
Dim ds As System.Security.AccessControl.DirectorySecurity
Dim account As System.Security.Principal.NTAccount
ds = System.IO.Directory.GetAccessControl(sfolder, System.Security.AccessControl.AccessControlSections.Owner)
account = New System.Security.Principal.NTAccount(System.Security.Principal.WindowsIdentity.GetCurrent.Name)
ds.SetOwner(account)
System.IO.Directory.SetAccessControl(sfolder, ds)
Application.DoEvents()
Catch ex As Exception
MessageBox.Show("" & ex.Message & "", "Take Ownership", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
Try
' Create a new DirectoryInfoobject.
Dim dInfo As New DirectoryInfo(FileName)
' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
' Set the new access settings.
dInfo.SetAccessControl(dSecurity)
Catch ex As Exception
MessageBox.Show("" & ex.Message & "", "Add Security", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
The first two Errors that appear is: Attempted to perform an unauthorized Operation, generated from the first time that AddDirectorySecurity and TakeOwnership are called.
I then get an error which states:
Access to the path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup' is denied.
This is generated from the directory.createdirectory line in DetectFolders sub
I'm rapidly beginning to run out of ideas to get this working. Is it something in my code? Am I missing something, or does windows 10 not work in this way. Any constructive help will be gratefully received.

How to update an MS Access database using a dataset in visual basic?

Hi I am currently working on a project on visual Basic 2010, what i am stuck on now is updating my MS Access database triggered by a button click.
I already have the connection and data adapter established and i generated a data set for the data adapter, and i have used the data set. what i am trying to do is read from a data grid view entries the user have typed in and save these changes to the data set, and finally save the dataset back into the database using the oledbdataadapter.update(dataset) command. I tried everything and i have been stuck for a while, there are no errors in the code and I can see the changes made to the dataset are successful and i can view them (i am getting the "update successful" at the end of the try so i am sure the code is executing till then and not going to exception), but i simply don't see the changes in the database.
below is the code, i will appreciate any help you can offer thank you.
For j As Integer = 6 To DataGridView1.Rows.Count
Try
Dim s As String = DataGridView1.Rows(j).Cells(0).Value
Dim Quantaties As Integer = DataGridView1.Rows(j).Cells(3).Value
For i As Integer = 0 To DataSet21.Tables("Stock").Rows.Count
Dim foundRow As DataRow = DataSet21.Tables("Stock").Rows.Find(i)
If foundRow IsNot Nothing Then
If foundRow(1) = s Then
DataSet21.Tables("Stock").Rows(i).Item(7) = Quantaties
DataSet21.AcceptChanges()
Try
Dim builder As New OleDbCommandBuilder(OleDbDataAdapter1)
Me.Validate()
OleDbDataAdapter1.UpdateCommand = builder.GetUpdateCommand()
OleDbDataAdapter1.Update(DataSet21.Stock)
DataSet21.AcceptChanges()
MsgBox("Update successful")
Catch ex As Exception
MsgBox("Update failed")
End Try
End If
End If
Next
BindingSource1.EndEdit()
Catch ex As Exception
End Try
Next
thank you for your reply.
I guess both ways work OleDbDataAdapter1.Update(DataSet21.Stock) and OleDbDataAdapter1.Update("DataSet21"), because i figured out what was wrong with my code. the problem was in the DataSet21.AcceptChanges() i should not have placed it before the OleDbDataAdapter1.Update(DataSet21.Stock).
the OleDbDataAdapter.update() saves changes done in the dataset to the database and the dataset.acceptchanges() makes the dataset save the changes done to it making it seem that it doesn't have changes in it anymore. so the OleDbDataAdapter.update() was not executing since the dataset didn't have changes done to it because of the dataset.acceptchanges()
so what i did was remove dataset.acceptchanges() and it finally worked. my code looks like this now.
For j As Integer = 6 To DataGridView1.Rows.Count
Try
Dim s As String = DataGridView1.Rows(j).Cells(0).Value
Dim Quantaties As Integer = DataGridView1.Rows(j).Cells(3).Value
For i As Integer = 0 To DataSet21.Tables("Stock").Rows.Count
Dim foundRow As DataRow = DataSet21.Tables("Stock").Rows.Find(i)
If foundRow IsNot Nothing Then
If foundRow(1) = s Then
DataSet21.Tables("Stock").Rows(foundRow(0) - 2).Item(7) = Quantaties
Try
BindingSource1.EndEdit()
OleDbDataAdapter1.Update(DataSet21.Stock)
MsgBox("Update successful")
Catch ex As Exception
MsgBox("Update failed")
End Try
End If
End If
Next
Catch ex As Exception
End Try
Next

VB.net TableAdapter.Update not updating database

I'm adding a new row to an Access 2010 database, and attempting to update the new row using TableAdapter.Update(). The code does not throw an exception, and it does not make a successful update to the database either. I've checked the original DB for changes, the one in the project folder, and the copy that is made in bin and there are no changes to any of them. Here is my code and any feedback would be greatly appreciated.
Private Sub insertRow(job As String, part As String, castDate As Date, inspectDate As Date, NCIR As Integer)
Dim row As As_Cast_DBDataSet.As_CastRow
Dim adapter As New As_Cast_DBDataSetTableAdapters.As_CastTableAdapter
row = Me.DBDataSet.As_Cast.NewAs_CastRow()
adapter = Me.As_CastTableAdapter
row.Job_Number = job
row.Part_Number = part
row.Casting_Date = castDate
row.Inspection_Date = inspectDate
row.NCIR = NCIR
Try
Me.DBDataSet.As_Cast.Rows.Add(row)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Try
adapter.Update(Me.DBDataSet.As_Cast)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Safe copy file in visual basic

The following code, was ripped out from a C# code. I wonder what is the importance of For.... To ...statement within the code?
Public Sub CopyFile(sourceFile As String, backupFile As String, overwrite As Boolean)
If String.IsNullOrEmpty(sourceFile) Then
Throw New ArgumentNullException("sourceFile")
End If
If String.IsNullOrEmpty(backupFile) Then
Throw New ArgumentNullException("backupFile")
End If
' According to MSDN Certain file attributes, Hidden and ReadOnly, can be combined. Other attributes, such as Normal, must be used alone.
If File.Exists(backupFile) Then
File.SetAttributes(backupFile, FileAttributes.Normal)
End If
' ????????
For index As Integer = 0 To 9
Try
File.Copy(sourceFile, backupFile, overwrite)
Exit Try
Catch ex As FileNotFoundException
Throw
Catch ex As Exception
If Not overwrite Then
Throw
End If
If index = 9 Then
Throw
End If
Thread.Sleep(1000)
End Try
Next
End Sub