|
|
I have never found a way to take advantage of thread names. Ideally one would give Thread instances a name, and be able to identify them by that name (rather than by a system-assigned number), however it does not work at all.
Furthermore, managed threads are virtual, there is no guaranteed one-to-one relationship with actual Windows threads, so you can't easily recognize your managed threads when looking at the output of tools such as Process Manager/TaskInfo
|
|
|
|
|
Hi all,
I have a vb.net application that uses dbase as the database.
When I run the application, if another application using the same dbase databse is open, the application crashes.
How to handle this case.
Any suggestions will be helpful.
Thanks in advance.
modified on Thursday, November 18, 2010 5:07 AM
|
|
|
|
|
A try/catch block around the code that gets a connection to the database?
|
|
|
|
|
Make sure that your app doesn't run when the other application is open. You can enumerate all the Windows on the desktop to check whether that's the case.
What version of dBase are you referring to? 4?
I are Troll
|
|
|
|
|
Thanks for the reply.
I'm using dbase IV.
|
|
|
|
|
Are you opening the dbase file in "Shared" mode ? Sounds like you are trying to access a resource with exclusive access and it cannot give it to you because someone else already has the resource.
I don't know the details of how to open a dbase file. I'm just talking theory here.
Good Luck.
|
|
|
|
|
Thanks for the reply.
The dbase file is not used in the shared mode.
Its on the server.
The same dbase file is used by another application and when that application is open, my application crashes.
|
|
|
|
|
Shared mode is for more than one concurrent user
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
An application crashing means you didn't take care of error and/or exception handling properly. Make sure you do, and the app will tell you what is wrong.
|
|
|
|
|
By using catch block and killing the running application, I solved this case.
Thanks for all those who replied and gave suggestions.
It help me to find a solution.
code:
Catch exp As Exception
MsgBox("The Database is used by Ariane. Easy ECN will exit Ariane now.")
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("db2krun")
For Each p As Process In pProcess
p.Kill()
Next
|
|
|
|
|
|
The exception is too general, that might hide problems later on. It'd be preferable to loop through the processes, and to exit if "db2krun" is running. Like this;
Dim pProcess() As Processes = System.Diagnostics.Process.GetProcessesByName("db2krun")
If pProcesses.Count > 0 Then
MsgBox("The Database is currently being used by Ariane. Easy ECN will exit now.")
Application.Terminate
End If
Most importantly, this code would cause your application to exit, as opposed to killing the other application. Imagine a grumpy old man, on a day without coffee. I've been typing in this Ariane for what feels like hours, and just when I'm about to hit the "save" button, and some guy kills the application! What's more, some applications refuse to restart if they're killed at the wrong moment.
The nice thing to do, is to refuse to start at all; the user hasn't any unsaved work in your application, it just began initializing.
I are Troll
|
|
|
|
|
I have been tasked to write an VB.Net application with all reports to be written in SSRS. I have never done SSRS so the first questions,
1. How can I print the report straight to printer and not first browser then print. Can this be done?
2. Can you create a PDF file and not first via browser
What would be the easiest and the fastest way to do these reports from VB.NET?
Thanks in advance.
|
|
|
|
|
This blog post[^] is about the closest you're going to get. It references SSRS 2000, but should still work for 2005. The code is in C#, but is easily converted to VB.NET using any of the online conversion tools.
|
|
|
|
|
Hi all
I has an vb.net application taht is developed in vs 2008.
I created a test cretificate in the Signing tab for test purpose.
Now I want to delete that certificate.
How to do that.
Any help will be helpful.
Thanks in advance.
modified on Thursday, November 18, 2010 3:35 AM
|
|
|
|
|
Start -> Run -> certmgr.msc
You'll probably find the certificate in the Personal folder. Delete JUST your code signing certificate. DO NOT DELETE ANY OTHER CERTIFICATES!
|
|
|
|
|
Thanks a lot.
I have deleted the certificate from the personal folder.
But I find the TemporaryKey.pfx file in my project and I also find in the Signing tab in the Sign the ClickOnce manifests the certificated issued is still displayed.
Ho to remove this?
Thanks in advance.
|
|
|
|
|
OK, so clear the checkbox next to "Sign the ClickOnce manifests" and delete the .pfx file from the project.
|
|
|
|
|
I deleted the .pfx file from the project and cleared the checkbox next to the signing.
But find that the inside the text box, the issued by, issued to ,etc ate displayed but disabled.
Once I check the ClickOnce manifests, it is again displayed active.
Will that affect while publishing the application?
Thanks.
|
|
|
|
|
If the checkbox is turned off, it won't be signed anymore, regardless of what's in the greyed out textbox.
|
|
|
|
|
Thanks for the reply.
I understand now.
|
|
|
|
|
I don't know how many times I've googled this and everything I've looked at doesn't give me a clear answer on what to do. I have file that has combined of many files. An example is |.jpeg|.txt|etc| (file). I know you can't delete from a encrypted file when shouldn't be all that hard to decrypt the file. However, my problem is deleting the .txt in the file.
There it will start out |.jpeg|.txt|etc|
but after running some code it will en up as |.jpeg|etc|
I've used fileStream which I've tried deleting from encrypted and decrypted files. Anything good will help.
|
|
|
|
|
Without more information, it's impossible to help you. You have to know what that file format is (office XML, .ZIP, .RAR, ...) that is holding these files. If it's a custom file format, you're going ot have to find a library or SDK that specifically handles it or write your own. But, in order to do that, you MUST know the exact details of what makes up the archive file format. Without that, you're SOL.
|
|
|
|
|
Well... its a custom made format(.fva). All files are encrypted and made into one file. Than when you want to extract from the file, the application will decrypt and extract the file for you. However, the location/position of the data within the file is in an xml but I'm not having any trouble with this part.
However one problem that's been annoying me for about a week is when you encryption small files, its hard to decrypt it(I'll post the code soon).
The second problem is when you delete from the datagridview. Here is the use case:
1. User selects file from datagridview.
2. User presses delete to delete the file.
3. Application deletes the file in the secure archive location.(this is the problem)
4. Application deletes the file from the xml.(not a problem)
5. Application keeps running until user exits out.
Here is the full code below. Please note I've deleted from the problem section because I've been trying things and googling alot lately.
Imports System.Xml
Imports System.Object
Imports System.Security
Imports System.Security.Cryptography
Imports System.IO
Imports System.IO.Compression
Imports Ionic.Zip
Public Class EncryptDecryptForm
Public index As Integer
Private Sub EncryptDecryptFormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
File_DataGridView.Rows.Clear()
Environment.Exit(0)
End Sub
Private Sub Encrypt_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Encrypt_Browse.Click
'The code below will open a dialog bos '
Dim find As OpenFileDialog = New OpenFileDialog()
find.Title = "File Vault application" 'Title of file browser'
find.InitialDirectory = "c:\"
find.AddExtension = True
find.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
find.FilterIndex = 2
find.RestoreDirectory = True
If find.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.Encrypt_TextBox.Text = find.FileName
End If
End Sub
Private Sub Decrypt_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Decrypt_Browse.Click
'Code below will start the folder browser'
Dim folder As FolderBrowserDialog = New FolderBrowserDialog()
folder.Description = "Select Folder"
folder.RootFolder = Environment.SpecialFolder.MyComputer
If folder.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.Decrypt_TextBox.Text = folder.SelectedPath.ToString
End If
End Sub
Private Sub Encrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Encrypt.Click
encryption()
End Sub
Private Sub reload()
'This functions reloads the datagrid with the new updated information'
'Replaces the format so the application can read it'
Dim xdoc As XmlDocument = New XmlDocument
xdoc.Load("Resources\FileVault.xml")
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim count As Integer
For count = 0 To (name.Count - 1)
File_DataGridView.Rows.Add(name.Item(count).InnerText.ToString, name.Item(count).InnerText.ToString)
Next count
File_DataGridView.AutoResizeColumns()
File_DataGridView.AutoResizeRows()
End Sub
Private Sub Decrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Decrypt.Click
decryption()
End Sub
Private Sub EncryptDecryptForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'When the forms load, this sets up the initial columns and what the user can and can not do to them.'
File_DataGridView.Columns.Add("File name", "File name")
File_DataGridView.ColumnHeadersVisible = True
File_DataGridView.ColumnCount = 1
File_DataGridView.AllowUserToResizeColumns = False
File_DataGridView.AllowUserToAddRows = False
File_DataGridView.AllowUserToResizeRows = False
File_DataGridView.AllowUserToOrderColumns = False
File_DataGridView.AllowDrop = False
File_DataGridView.AllowUserToDeleteRows = True
File_DataGridView.AutoGenerateColumns = True
Dim xdoc As XmlDocument = New XmlDocument
xdoc.Load("Resources\FileVault.xml") 'Load Xml file -> declare location here'
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******") 'Counts these elements'
Dim count As Integer
For count = 0 To (name.Count - 1) 'This for loop fills the data'
File_DataGridView.Rows.Add(name.Item(count).InnerText.ToString, name.Item(count).InnerText.ToString)
Next count
End Sub
'This function creates the encryption key'
Private Function keyencryption(ByVal strPassword As String) As Byte()
'Converting the character to an array and storing the data
Dim chrdata() As Char = strPassword.ToCharArray
'Make is the same length'
Dim Length As Integer = chrdata.GetUpperBound(0)
'starting to hash the data'
Dim bytDataToHash(Length) As Byte
For i As Integer = 0 To chrdata.GetUpperBound(0)
bytDataToHash(i) = CByte(Asc(chrdata(i)))
Next
'Declaring what Hash to use'
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
'Hashing'
Dim Result As Byte() = SHA512.ComputeHash(bytDataToHash)
Dim resIV(31) As Byte
For i As Integer = 0 To 31
resIV(i) = Result(i)
Next
Return resIV
End Function
'Identical function from above except for a few lines
Private Function IVCreation(ByVal strPassword As String) As Byte()
'Converting the character to an array and storing the data
Dim chrdata() As Char = strPassword.ToCharArray
'Make is the same length'
Dim Length As Integer = chrdata.GetUpperBound(0)
'starting to hash the data'
Dim bytDataToHash(Length) As Byte
For i As Integer = 0 To chrdata.GetUpperBound(0)
bytDataToHash(i) = CByte(Asc(chrdata(i)))
Next
'Declaring what Hash to use'
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
'Hashing'
Dim Result As Byte() = SHA512.ComputeHash(bytDataToHash)
Dim resIV(15) As Byte
For i As Integer = 32 To 47
resIV(i - 32) = Result(i)
Next
Return resIV
End Function
Private Function encryption()
'This sub will encrypt the file, xml edits, update the gridview'
'loading the xml document'
Dim xdoc As XmlDocument = New XmlDocument
Dim key As Byte()
Dim IV As Byte()
'The hardcoded password goes here'
'This is a section just in case you want to a password to your encrypted files'
'Right now it uses the hardcoded password'
'If you can expand this if you want'
key = keyencryption(LoginForm.Password_TextBox.Text)
IV = IVCreation(LoginForm.Password_TextBox.Text)
'if there is an error in the application. A error message will be displayed'
Try
'checking to make sure the text box isn't null'
If (Encrypt_TextBox.Text = "") Then
MessageBox.Show("Need to put in a file location")
Else
'Grabing the file name'
Dim locatefilename As String = Me.Encrypt_TextBox.Text
Dim i As Integer = 0
Dim fnPosition As Integer = 0
'locating all the \ in the string'
While locatefilename.IndexOf("\"c, i) <> -1
fnPosition = locatefilename.IndexOf("\"c, i)
i = fnPosition + 1
End While
Dim junk As String
Dim tfile As String
Dim file As String
Dim ext As String
'This should get all the junk that not need for saving files'
'This should capture what you don't need'
junk = locatefilename.Substring(0, fnPosition)
'This should capture the file'
tfile = locatefilename.Substring(fnPosition + 1)
'Zeroing both i and fnPosition'
i = 0
fnPosition = 0
'taking out the extention in the file and saving it to the xml'
While tfile.IndexOf("."c, i) <> -1
fnPosition = tfile.IndexOf("."c, i)
i = fnPosition + 1
End While
'This should get the actually file name'
file = tfile.Substring(0, fnPosition)
'captures the ext (like the txt)'
'Makes the format of the file invisible but only in the xml'
ext = "." & tfile.Substring(fnPosition + 1)
'Checking to make sure there are not duplicate file name'
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim cname As Integer
For cname = 0 To (name.Count - 1)
If (file = name.Item(cname).InnerText) Then
MessageBox.Show("Duplicate file name - either delete the file present in safe or rename file")
Return 1
End If
Next
'This is the file being read in'
Dim fileinput As New System.IO.FileStream(Me.Encrypt_TextBox.Text, IO.FileMode.Open, IO.FileAccess.Read)
'specific file output location here
Dim fileoutput As New System.IO.FileStream("*******", IO.FileMode.Open, IO.FileAccess.Write)
Dim start As Integer = fileoutput.Length
'Declaring variables for encryption'
Dim buffer(4096) As Byte 'Holds the bytes for processing
Dim BytesProcessed As Long = 0 'running count for bytes that are processed'
Dim filelength As Long = fileinput.Length 'Length of file coming in'
Dim bytesinblock As Integer 'current bytes in block'
Dim crypto As CryptoStream
'Declaring crypto service provider'
Dim scRijndael As New System.Security.Cryptography.RijndaelManaged
'setting up progress bars
Encrypt_ProgressBar.Value = 0
Encrypt_ProgressBar.Maximum = 100
crypto = New CryptoStream(fileoutput, scRijndael.CreateEncryptor(key, IV), CryptoStreamMode.Write)
While BytesProcessed < filelength
'reading the file'
bytesinblock = fileinput.Read(buffer, 0, 4096)
'writing the file to cryptoStream'
crypto.Write(buffer, 0, bytesinblock)
'updating bytes processed'
BytesProcessed = BytesProcessed + CLng(bytesinblock)
'equation for updating bytes in block'
Encrypt_ProgressBar.Value = CInt((BytesProcessed / filelength) * 100)
End While
Dim filend As Integer = fileoutput.Length
crypto.Close()
fileinput.Close()
fileoutput.Close()
MessageBox.Show("File is done encrypting")
Encrypt_ProgressBar.Step = 0
Encrypt_ProgressBar.Value = 0
Encrypt_TextBox.Text = ""
'End While
'loading the xml file
xdoc.Load("*******")
'variable for adding a new line'
Dim nline As String = Environment.NewLine
'Creating string for xml file with proper formats'
Dim xmlString As String = nline & " <file>" & nline & " <name>" & file & "</name>" & nline & " <location>" & "Safe\" & file & "</location>" & nline & " <ext>" & ext & "</ext>" & nline & " <beginbyte>" & start & "</beginbyte>" & nline & " <endbytes>" & filend & "</endbytes>" & nline & " </file>" & nline
'the following is used to add the element to the xml'
Dim frag As XmlDocumentFragment = xdoc.CreateDocumentFragment
'Adds the xmlstring to the frag'
frag.InnerXml = xmlString
Dim xroot As XmlNode = xdoc.DocumentElement
'the following statements will add on to the file and save the file'
xroot.AppendChild(frag)
xdoc.Save("*******")
'Clearing the datagrid and reloading the new data, to the eye it you will just blink'
File_DataGridView.Hide()
File_DataGridView.Rows.Clear()
'function reloads the updated xml file'
reload()
File_DataGridView.Show()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return 1
End Function
Private Function decryption()
'This is function is the same as encryption with just a few changes'
'loading the xml document'
Dim xdoc As XmlDocument = New XmlDocument
Dim key As Byte()
Dim IV As Byte()
'The hardcoded password goes here'
'This is a section just in case you want to a password to your encrypted files'
key = keyencryption(LoginForm.Password_TextBox.Text)
IV = IVCreation(LoginForm.Password_TextBox.Text)
'if there is an error in the application. A error message will be displayed'
Try
'checking to make sure the text box isn't null'
If (Decrypt_TextBox.Text = "") Then
MessageBox.Show("Need to put in the file location or select file in grid for decryption")
Else
'declaring string for file'
Dim file As String
Dim tfile As String
Dim deleteExt As String
Dim output As String
Dim fnPosition As Integer
Dim i As Integer
'locating the selected file in the gridview'
'loading the xml file
xdoc.Load("*******")
'Declare name for xml node'
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******")
'file location is now saved
file = name.Item(index).InnerText
'Substring of file. This is will be convering the file back to its normal
tfile = file.Substring(5)
'retrieving the extenstion'
Dim extname As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim replace As String
deleteExt = extname.Item(index).InnerText
'replacing with proper format'
While tfile.IndexOf("."c, i) <> -1
fnPosition = tfile.IndexOf("."c, i)
i = fnPosition + 1
End While
'This should get the actually file name'
replace = (tfile & deleteExt)
'setting the output file with proper format'
output = Decrypt_TextBox.Text & "\" & replace
Dim filebegin As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim filend As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim intStart As Integer = filebegin.Item(index).InnerText
Dim intEnd As Integer = filend.Item(index).InnerText
'This is go into the Safe and retrieve file'
Dim fileinput As New System.IO.FileStream("Safe.fva", IO.FileMode.Open, IO.FileAccess.Read)
'specific file output location wiht proper extension'
Dim fileoutput As New System.IO.FileStream(output, IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
'The next line makes sure that the file is empty'
fileoutput.SetLength(0)
'Declaring variables for encryption'
Dim buffer(4096) As Byte 'Holds the bytes for processing
Dim BytesProcessed As Long = 0 'running count for bytes that are processed'
Dim filelength As Long = intEnd - intStart 'Length of file coming in where intEnd will be greater than intStart'
Dim bytesinblock As Integer 'current bytes in block
Dim crypto As CryptoStream
'Declaring crypto service provider'
Dim scRijndael As New System.Security.Cryptography.RijndaelManaged
'setting up progress bars
Encrypt_ProgressBar.Value = 0
Encrypt_ProgressBar.Maximum = 100
crypto = New CryptoStream(fileoutput, scRijndael.CreateDecryptor(key, IV), CryptoStreamMode.Write)
fileinput.Position = intStart
While BytesProcessed < filelength
'reading the file'h
bytesinblock = fileinput.Read(buffer, 0, 4096)
'writing the file to cryptoStream'
crypto.Write(buffer, 0, bytesinblock)
'updating bytes processed'
BytesProcessed = BytesProcessed + CLng(bytesinblock)
'equation for updating bytes in block'
Decrypt_ProgressBar.Value = CInt((BytesProcessed / filelength) * 100)
End While
If (filelength = 0) Then
bytesinblock = fileinput.Read(buffer, 0, 4096)
crypto.Write(buffer, 0, bytesinblock)
End If
crypto.Close()
fileinput.Close()
fileoutput.Close()
MessageBox.Show("File is done decrypting")
Decrypt_ProgressBar.Step = 0
Decrypt_ProgressBar.Value = 0
Decrypt_TextBox.Text = ""
End If
Catch ex As Exception
MsgBox(ex.StackTrace.ToString)
End Try
Return 1
End Function
Public Sub File_DataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles File_DataGridView.CellClick
index = e.RowIndex
End Sub
Private Sub File_DataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles File_DataGridView.UserDeletingRow
Dim xdoc As XmlDocument = New XmlDocument
xdoc.Load("*******")
Dim filebegin As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim filend As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim intStart As Integer = filebegin.Item(index).InnerText
Dim intEnd As Integer = filend.Item(index).InnerText
Dim deletefile As New System.IO.FileStream("*******", FileMode.Open)
Dim deletethis As Integer = CLng(deletefile.Length)
'Deletes the actual file'
Dim location As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim del_location As String = location.Item(index).InnerText
'Deletes the information in the xml'
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******")
name.Item(index).RemoveAll()
name.Item(index).ParentNode.RemoveChild(name.Item(index))
xdoc.Save("********")
End Sub
End Class
All help will be greatly appriecated.
|
|
|
|
|