Detach database failed for Server 'MONO-PC\SQLEXPRESS' - vb.net

Error : "Detach database failed for Server 'MONO-PC\SQLEXPRESS'."
Public Sub bk()
Try
Dim strDatabasePath As String = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath, "LIC.mdf")
Dim strdbLogPath As String = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath, "LIC_log.ldf")
' DB.Connection can be any valid SQLConnection which you might already be using in your application
Dim con As New SqlClient.SqlConnection(LIC.My.Settings.LICConnectionString)
Dim srvCon As New ServerConnection(con)
Dim srv As Server = New Server(srvCon)
If srv.Databases.Contains(strDatabasePath) Then
If Not con.State = ConnectionState.Closed Then
con.Close()
End If
srv.DetachDatabase(strDatabasePath, True)
My.Computer.FileSystem.CopyFile(strDatabasePath, "c:\backup\LIC.mdf", True)
My.Computer.FileSystem.CopyFile(strdbLogPath, "c:\backup\LIC_log.ldf", True)
MessageBox.Show("Backup taken successfully")
End If
srvCon.Disconnect()
con.Open()
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
End Sub
Why does it fail??Any Help Appreciated.

You should not use the path for the database name and you should extract the file names from the database object. Here is a rewrite that will work for any database:
Public Sub bk()
Try
Using con As New SqlClient.SqlConnection(LIC.My.Settings.LICConnectionString)
Dim sDatabaseName As String
con.Open()
sDatabaseName = con.Database
con.Close()
Dim srvCon As New ServerConnection(con)
Dim srv As Server = New Server(srvCon)
If srv.Databases.Contains(sDatabaseName) Then
Dim oDatabase As Database
Dim cFiles As New List(Of String)
' Get a local reference to the database
oDatabase = srv.Databases(sDatabaseName)
' Collect the list of database files associated with this database
For Each oFileGroup As FileGroup In oDatabase.FileGroups
For Each oFile As DataFile In oFileGroup.Files
cFiles.Add(oFile.FileName)
Next
Next
' And collect the list of log files associated with this database
For Each oFile As LogFile In oDatabase.LogFiles
cFiles.Add(oFile.FileName)
Next
' Ensure nothing is using the database
srv.KillAllProcesses(sDatabaseName)
' Detach the database
srv.DetachDatabase(sDatabaseName, False)
' And finally, copy all of the files identified above to the backup directory
For Each sFileName As String In cFiles
System.IO.File.Copy(sFileName, System.IO.Path.Combine("c:\backup\", System.IO.Path.GetFileName(sFileName)), True)
Next
MessageBox.Show("Backup taken successfully")
End If
srvCon.Disconnect()
End Using
Catch ex As Exception
MessageBox.Show("Error Occured : " & ex.Message)
End Try
End Sub

Related

oracle bulkcopy from vb.net databale

I am loading the CSV file to vb.net datatable .
then I am using Bulk copy command to write to database.
The problem is if one date cell in the data table is empty, i am receiving
ORA:-01840 input value not long enough for date format.
How to resolve this.
Public Class Form1
Dim cn As New OracleConnection("Data Source =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = ipaddressofserver)(PORT = portofserver))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = oracleservicename)) ) ; User Id=useridofdb;Password=passwordofdb")
cn.Open()
MsgBox("connection opened")
Dim dt As DataTable = ReadCSV("D:\test.csv")
DataGridView1.DataSource = dt
Try
Dim _bulkCopy As New OracleBulkCopy(cn)
_bulkCopy.DestinationTableName = "TEST_TABLE"
_bulkCopy.BulkCopyTimeout = 10800
_bulkCopy.WriteToServer(dt)
cn.Close()
cn.Dispose()
cn = Nothing
MsgBox("Finished")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Function ReadCSV(ByVal path As String) As System.Data.DataTable
Try
Dim sr As New StreamReader(path)
Dim fullFileStr As String = sr.ReadToEnd()
sr.Close()
sr.Dispose()
Dim lines As String() = fullFileStr.Split(ControlChars.Lf)
Dim recs As New DataTable()
Dim sArr As String() = lines(0).Split(","c)
For Each s As String In sArr
recs.Columns.Add(New DataColumn())
Next
Dim row As DataRow
Dim finalLine As String = ""
For Each line As String In lines
row = recs.NewRow()
finalLine = line.Replace(Convert.ToString(ControlChars.Cr), "")
row.ItemArray = finalLine.Split(","c)
recs.Rows.Add(row)
Next
Return recs
Catch ex As Exception
Throw ex
End Try
End Function
End Class

SqlFileStream writing in separate thread not working

Learning and testing using Sql FILESTREAM for a web app. A client uploads a large file form the web page which takes 'X' time and when fully uploaded shows 100% complete. However, very large files also take time for SqlFileStream to write to the file system so I want to spin off a thread to complete that part. The code I've got seems to work fine but no data ends up in the filestream file.
I'm wrapping the initial record creation in it's own transaction scope and using a separate transaction scope in the thread. In the threaded routine I have the appropriate PathName() and TransactionContext but I assume I'm missing something while using a thread.
I've commented out the normal SqlFileStream call which works fine. Can you see anything wrong with what I'm doing here?
Public Function StoreFileStream()
Dim json As New Dictionary(Of String, Object)
Dim parms As New FileStreamThreadParameters
If HttpContext.Current.Request.Files.Count > 0 Then
Dim file As HttpPostedFile = HttpContext.Current.Request.Files(0)
If "contentType" <> String.Empty Then
Dim fs As Stream = file.InputStream
Dim br As New BinaryReader(fs)
Dim noBytes As New Byte()
Try
Dim filePath As String = ""
Dim trxContext As Byte() = {}
Dim baseFileId As Integer
Using trxScope As New TransactionScope
Using dbConn As New SqlConnection(DigsConnStr)
Using dbCmd As New SqlCommand("ADD_FileStreamFile", dbConn)
dbConn.Open()
Using dbRdr As SqlDataReader = dbCmd.ExecuteReader(CommandBehavior.SingleRow)
dbRdr.Read()
If dbRdr.HasRows Then
filePath = dbRdr("Path")
trxContext = dbRdr("TrxContext")
baseFileId = dbRdr("BaseFileID")
End If
dbRdr.Close()
End Using
' Code below writes to file, but trying to offload this to a separate thread so user is not waiting
'Using dest As New SqlFileStream(filePath, trxContext, FileAccess.Write)
' fs.CopyTo(dest, 4096)
' dest.Close()
'End Using
End Using
dbConn.Close()
End Using
trxScope.Complete()
End Using ' transaction commits here, not in line above
parms.baseFileId = baseFileId
parms.fs = New MemoryStream
fs.CopyTo(parms.fs)
Dim fileUpdateThread As New Threading.Thread(Sub()
UpdateFileStreamThreaded(parms)
End Sub)
fileUpdateThread.Start()
json.Add("status", "success")
Catch ex As Exception
Elmah.ErrorSignal.FromCurrentContext().Raise(ex)
json.Add("status", "failure")
json.Add("msg", ex.Message)
json.Add("procedure", System.Reflection.MethodBase.GetCurrentMethod.Name)
End Try
Else
json.Add("status", "failure")
json.Add("msg", "Invalid file type")
json.Add("procedure", System.Reflection.MethodBase.GetCurrentMethod.Name)
End If
End If
Return json
End Function
Public Class FileStreamThreadParameters
Public Property baseFileId As Integer
Public fs As Stream
End Class
Private Sub UpdateFileStreamThreaded(parms As FileStreamThreadParameters)
Dim filePath As String = ""
Dim trxContext As Byte() = {}
Try
Using trxScope As New TransactionScope
Using dbConn As New SqlConnection(DigsConnStr)
Using dbCmd As New SqlCommand("SELECT FileBytes.PathName() 'Path', GET_FILESTREAM_TRANSACTION_CONTEXT() 'TrxContext' FROM FileStreamFile WHERE Id = " & parms.baseFileId, dbConn)
dbConn.Open()
Using dbRdr As SqlDataReader = dbCmd.ExecuteReader(CommandBehavior.SingleRow)
dbRdr.Read()
If dbRdr.HasRows Then
filePath = dbRdr("Path")
trxContext = dbRdr("TrxContext")
End If
dbRdr.Close()
Using dest As New SqlFileStream(filePath, trxContext, FileAccess.Write)
parms.fs.CopyTo(dest, 4096)
dest.Close()
End Using
End Using
End Using
dbConn.Close()
End Using
trxScope.Complete()
End Using
Catch ex As Exception
'Elmah.ErrorSignal.FromCurrentContext().Raise(ex)
End Try
End Sub
Obviously this is a complex issue. I actually got it to work with the code below. However I eventually abandoned using SQL FILESTREAM altogether due to too much complexity in getting it all set up.
This is an existing web application with the sql server on a different box. After I got the filestreaming to work the next hurdle was authentication setup. Filestream requires Integrated Security on your connection string. Even with windows authentication on our Intranet app, I could not get the web app to use the windows credentials when connecting to the database. It always seemed to use the computer name or the app pool service. I tried many many examples I found on the net and here to no avail. Even if I got that to work then I would want to use and Active Directory group over individual logins which looked to be another hurdle.
This app stores documents in a varbinary column so that full text search can be enabled at some point. The issue was with large files which are generally pictures or videos. Since you can't search text on those anyway the strategy now is to store those on the file system and all other searchable docs (.docx, .pptx, etc) will still be stored in the varbinary. I'm actually sad that I could not get filestream to work as it seems like the ideal solution. I'll come back to it some day but it really should not be so frickin complicated. :-(
The code I got working is:
Dim filePath As String = ""
Dim trxContext As Byte() = {}
Dim baseFileId As Integer
Using trxScope As New TransactionScope
Using dbConn As New SqlConnection(DigsFSConnStr)
Using dbCmd As New SqlCommand("NEW_FileStreamBaseFile", dbConn)
dbCmd.CommandType = CommandType.StoredProcedure
dbCmd.Parameters.AddWithValue("#Title", fileDesc)
dbCmd.Parameters.AddWithValue("#Summary", summary)
dbCmd.Parameters.AddWithValue("#Comments", comments)
dbCmd.Parameters.AddWithValue("#FileName", uploadedFileName)
dbCmd.Parameters.AddWithValue("#ContentType", contentType)
dbCmd.Parameters.AddWithValue("#FileExt", ext)
'dbCmd.Parameters.AddWithValue("#FileBytes", noBytes) ' now that were offloading the file byte storage to a thread
dbCmd.Parameters.AddWithValue("#UploadedByResourceID", uploadedByResourceID)
dbCmd.Parameters.AddWithValue("#UploadedByShortName", uploadedByShortName)
dbCmd.Parameters.AddWithValue("#FileAuthor", fileAuthor)
dbCmd.Parameters.AddWithValue("#TagRecID", tagRecID)
dbCmd.Parameters.AddWithValue("#UserID", samAccountName)
dbCmd.Parameters.AddWithValue("#FileDate", fileDate)
dbCmd.Parameters.AddWithValue("#FileType", fileType)
dbCmd.Parameters.AddWithValue("#FileTypeRecID", fileTypeRecId)
' Save to file system too for xod conversion
file.SaveAs(HttpContext.Current.Server.MapPath("~/files/uploaded/") & uploadedFileName)
dbConn.Open()
Using dbRdr As SqlDataReader = dbCmd.ExecuteReader(CommandBehavior.SingleRow)
dbRdr.Read()
If dbRdr.HasRows Then
filePath = dbRdr("Path")
trxContext = dbRdr("TrxContext")
json.Add("baseFileId", dbRdr("BaseFileID"))
virtualFileRecId = dbRdr("VirtualFileRecID")
dbStatus = dbRdr("status")
If dbStatus = "failure" Then
json.Add("msg", dbRdr("msg"))
End If
End If
dbRdr.Close()
End Using
' Prepare and start Task thread to write the file
If dbStatus = "success" Then
bytes = br.ReadBytes(fs.Length)
Dim task As New System.Threading.Tasks.Task(
Sub()
UpdateNewFileStreamBytes(virtualFileRecId, bytes)
End Sub)
task.Start()
json.Add("status", "success")
Else
json.Add("status", "failure")
End If
End Using
dbConn.Close()
End Using
trxScope.Complete()
End Using ' transaction commits here, not in line above
With the task procedure of:
Private Sub UpdateNewFileStreamBytes(virtualFileRecId As Integer, fileBytes As Byte())
Dim filePath As String = ""
Dim trxContext As Byte() = {}
Try
Using trxScope As New TransactionScope
Using dbConn As New SqlConnection(DigsFSConnStr)
Using dbCmd As New SqlCommand("UPD_FileStreamBaseFile", dbConn)
dbCmd.CommandType = CommandType.StoredProcedure
dbCmd.Parameters.AddWithValue("#VirtualFileRecID", virtualFileRecId)
dbConn.Open()
Using dbRdr As SqlDataReader = dbCmd.ExecuteReader(CommandBehavior.SingleRow)
dbRdr.Read()
If dbRdr.HasRows Then
filePath = dbRdr("Path")
trxContext = dbRdr("TrxContext")
End If
dbRdr.Close()
Using dest As New SqlFileStream(filePath, trxContext, FileAccess.Write)
dest.Write(fileBytes, 0, fileBytes.Length)
dest.Close()
End Using
End Using
End Using
dbConn.Close()
End Using
trxScope.Complete()
End Using
Catch ex As Exception
Elmah.ErrorSignal.FromCurrentContext().Raise(ex)
End Try

How to do DB backup with VistaDB?

I'm trying to do a XML export of the database with VistaDB.
Unfortuanently, I'm lost.
Here's my code so far:
Dim instance As IVistaDBDatabase
Dim value As System.Int64
SaveFileDialog2.InitialDirectory = "C:\"
Select Case SaveFileDialog2.ShowDialog()
Case Windows.Forms.DialogResult.OK
Try
instance.ExportXml(SaveFileDialog2.FileName, VistaDBXmlWriteMode.All)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Select
All I get is object not set to instance of an object (or something like that).
Can anyone provide so guidance?
I was able to figure it out with help from an old code package.
Here is the proper code:
Dim vdbDatabase As IVistaDBDatabase = Nothing
Dim filenameDB As String = SaveFileDialog2.FileName
Dim filenameXML As String = SaveFileDialog2.FileName
Select Case SaveFileDialog2.ShowDialog()
Case System.Windows.Forms.DialogResult.OK
Try
' Call the method that will open the connection to the database and return an open IVistaDBDatabase object for the database to us
vdbDatabase = DDA.VistaDBEngine.Connections.OpenDDA.OpenDatabase("C:\Ledger.vdb5", VistaDBDatabaseOpenMode.NonexclusiveReadOnly, Nothing)
' Clear the XML Transfer List - this is the list used by the Import/Export methods
vdbDatabase.ClearXmlTransferList()
' Loop through the tables in the database and add them to the XmlTransferList
For Each tableName As String In vdbDatabase.GetTableNames()
vdbDatabase.AddToXmlTransferList(tableName)
Next
' Call the ExportXML method with the name of the XML file and the WriteMode value indicating what to Export
vdbDatabase.ExportXml(filenameXML, VistaDBXmlWriteMode.All)
' If the database is open - close it
If Not vdbDatabase.IsClosed Then
vdbDatabase.Close()
End If
MsgBox("Database Export complete.", MsgBoxStyle.Information)
Catch ex As Exception
WriteErrorEvent("Error exporting Database in addin", ex)
MsgBox("An error occured attempting to export the Database. Error Message:" & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Exclamation)
Finally
' If we have a vdbDatabase object
If Not (vdbDatabase Is Nothing) Then
' If it is open, close it
If Not vdbDatabase.IsClosed Then
vdbDatabase.Close()
End If
' Dispose of the object
vdbDatabase.Dispose()
End If
End Try
End Select
A Little late but i've made a small change to your code, so you can see the exact time of your backup.
Dim vdbDatabase As IVistaDBDatabase = Nothing
Dim filenamedb As String = vdbDatabase
Dim filenameXML As String = "MyDataBaseName_" + Now.ToString("dd-MM-yyyy_hh-mm-ss") + ".Xml"
Dim path As String
path = System.IO.Path.GetFullPath(filenameXML)
Try
vdbDatabase = DDA.VistaDBEngine.Connections.OpenDDA.OpenDatabase("DataDirectory|MyDataBase.vdb5", VistaDBDatabaseOpenMode.NonexclusiveReadOnly, Nothing)
vdbDatabase.ClearXmlTransferList()
For Each tableName As String In vdbDatabase.GetTableNames()
vdbDatabase.AddToXmlTransferList(tableName)
Next
vdbDatabase.ExportXml(filenameXML, VistaDBXmlWriteMode.All)
If Not vdbDatabase.IsClosed Then
vdbDatabase.Close()
End If
MsgBox("Backup is in " + path, MsgBoxStyle.Information)
Catch ex As Exception
MsgBox("An error occured attempting to export the Database. Error Message:" & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Exclamation)
Finally
If Not (vdbDatabase Is Nothing) Then
If Not vdbDatabase.IsClosed Then
vdbDatabase.Close()
End If
vdbDatabase.Dispose()
End If
End Try

VB.NET - "Cannot access a closed file" when trying to read contents of a file

Here is my code for the form...
I am attempting to read the contents of files to be able to store in a DB as blob
Try
Dim fs = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read)
Dim rawData = New Byte(fs.Length) {}
fs.Read(rawData, 0, fs.Length)
fs.Close()
' Get File size
Dim filesize As Long = fs.Length
' Get Extension
Dim extension As String = Path.GetExtension(TextBox1.Text)
'SQL query
Dim cmdText = "INSERT INTO files VALUES (file_id, #fname, #content, #size, #ext, #comments, #vers, #auth);"
'commit SQL query with connection statement
Dim com As New MySqlCommand(cmdText, con)
'place fields into parameters for the query
com.Parameters.AddWithValue("#fname", filename.Text)
com.Parameters.AddWithValue("#content", rawData)
com.Parameters.AddWithValue("#size", filesize)
com.Parameters.AddWithValue("#ext", extension)
com.Parameters.AddWithValue("#comments", comments.Text)
com.Parameters.AddWithValue("#vers", version.Text)
com.Parameters.AddWithValue("#auth", home.userid.Text)
'this will commit the record to the DB
con.Close()
con.Open()
com.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
As seen in the link below, Length property can throw IOException if the file is closed or closing
http://msdn.microsoft.com/en-us/library/system.io.filestream.length.aspx
You are accessing the length after closing the file. just flip them as shown below
' Get File size
Dim filesize As Long = fs.Length
fs.Close()

How to save and retrieve a fingerprint template in phpmyadmin database, using VB

We are using digital persona for our biometrics. We can already save employee ID, employee name and assigned finger .Our problem is that we dont know how to save a fingerprint template to a database and retrieve it so that it can still be read and verified by the biometric scanner. The file extension is ".ftp" .
CODE:
Private Sub buttonRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonRegister.Click
'Does user already exists
Dim bUserExists As Boolean = _Users.UserExists(New UserID(textBoxUserName.Text))
' first make sure the user is created if new user
If _ActiveUser Is Nothing Or Not bUserExists Then
' initialize with supplied user name
_ActiveUser = New User(textBoxUserName.Text)
Else
' update active user if not as originally selected
If bUserExists And Not listBoxUsers.SelectedItem.ToString() = textBoxUserName.Text Then
_ActiveUser = _Users(New UserID(textBoxUserName.Text))
End If
End If
' and check if the template already exists for the assigned finger
If _ActiveUser.TemplateExists(_AssignedFinger) Then
' show message indicating template already exists for selected finger
Dim diagResult As DialogResult = MessageBox.Show(Me, [String].Format("Oops!" + ControlChars.Cr + ControlChars.Lf + "{0} has a template enrolled to his/her {1} finger." + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf + "Shall the old template be discarded?", _ActiveUser.ID.ToString(), _Fingers(_AssignedFinger)), "Template already assigned!", MessageBoxButtons.YesNo, MessageBoxIcon.Error)
' if user selected not to overwrite, then abort
If diagResult = Windows.Forms.DialogResult.No Then
Return
End If
End If
Try
' attempt to read the template
Dim templateOpened As New DPFP.Template(File.OpenRead(textBoxTemplateFilename.Text))
' run a template duplicate check
IdentifyTemplate(templateOpened)
' remove the old template if exists
If _ActiveUser.TemplateExists(_AssignedFinger) Then
' removed from assigned finger
_ActiveUser.RemoveTemplate(_AssignedFinger)
End If
' and assign it to the user as specified
_ActiveUser.AddTemplate(templateOpened, _AssignedFinger)
' update collection
If Not _Users.UserExists(_ActiveUser.ID) Then
' update list box
listBoxUsers.Items.Add(_ActiveUser.ID.ToString())
' add user it to the user collection
_Users.AddUser(_ActiveUser)
End If
' success
UpdateEventLog([String].Format("{0}: Template successfully assigned to {1} finger.", _ActiveUser.ID.ToString(), _AssignedFinger.ToString()))
' turn off groupbox
groupAddTemplate.Visible = False
listBoxUsers.SelectedItem = _ActiveUser.ID.ToString()
' sync gui
_syncUI()
' view user
_syncViewUser()
Catch Err As DPFP.Error.SDKException
' log message
UpdateEventLog(Err.ToString())
System.Diagnostics.Trace.WriteLine(Err.ToString())
Catch Err As System.IO.FileNotFoundException
' log message
UpdateEventLog("Template file not found or is inaccessible.")
System.Diagnostics.Trace.WriteLine(Err.ToString())
Catch Err As Exception
' log message
UpdateEventLog(Err.ToString())
System.Diagnostics.Trace.WriteLine(Err.ToString())
End Try
Using conn As New MySqlConnection("Server = localhost; Username= root; Password =; Database = vb")
Using cmd
With cmd
MsgBox("Connection Established")
.Connection = conn
.Parameters.Clear()
'Create Insert Query
.CommandText = "INSERT INTO employees(UserID, Name, Finger) VALUES (#iID, #iName, #iFinger)"
.Parameters.Add(New MySqlParameter("#iID", ID.Text))
.Parameters.Add(New MySqlParameter("#iName", textBoxUserName.Text))
.Parameters.Add(New MySqlParameter("#iFinger", comboBoxAssignedFinger.Text))
End With
Try
'Open Connection and Execute Query
conn.Open()
cmd.ExecuteNonQuery()
Catch ex As MySqlException
MsgBox(ex.Message.ToString())
End Try
End Using
End Using
i know that this is an old post but here are code blocks that might help...
IN SAVING I USED THIS
For Each template As DPFP.Template In Data.Templates
If Not template Is Nothing Then
cmd = New MySqlCommand("INSERT INTO employeefp " +
"SET No=#No, " +
"FP=#FP " +
" ", conn)
cmd.Parameters.Add(New MySqlParameter("#No", txtEmpNo.Text))
cmd.Parameters.Add(New MySqlParameter("#FP", template.Bytes))
cmd.ExecuteNonQuery()
End If
Next
IN VERIFYING FROM THE DB I USED THIS
WHEN FORM IS LOADED I FETCH ALL THE FINGER PRINTS
Dim cmd As New MySqlCommand("SELECT * FROM employeefp ", conn)
Dim rdr As MySqlDataReader = cmd.ExecuteReader()
While (rdr.Read())
Dim MemStream As IO.MemoryStream
Dim fpBytes As Byte()
fpBytes = rdr("FP")
MemStream = New IO.MemoryStream(fpBytes)
Dim templa8 As DPFP.Template = New DPFP.Template()
templa8.DeSerialize(MemStream)
Dim tmpObj As New AppData
tmpObj.No = rdr("No").ToString()
tmpObj.Template = templa8
FPList.Add(tmpObj)
End While
NOTE : Dim FPList As List(Of AppData) = New List(Of AppData) //you can find the definition of this in the SDK i just added Template (contains one print) aside from the existing Templates(contains many print)
COMPARE THE CURRENT SAMPLE FROM THE MACHINE
Sub OnComplete(ByVal Control As Object, ByVal FeatureSet As DPFP.FeatureSet, ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus) Handles VerificationControl.OnComplete
Dim printFound As Boolean = False
VerifiedFPData = New AppData
Try
For Each FPData As AppData In FPList
Dim tmplateData As New DPFP.Template
tmplateData = FPData.Template
Dim compareTo As New DPFP.FeatureSet
compareTo = FeatureSet
Dim ver As New DPFP.Verification.Verification()
Dim res As New DPFP.Verification.Verification.Result()
If Not tmplateData Is Nothing Then
ver.Verify(FeatureSet, tmplateData, res)
If res.Verified Then
EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Success
printFound = True
VerifiedFPData = FPData
Exit For ' success
End If
End If
Next
Catch ex As Exception
MessageBox.Show("verification error")
End Try
If printFound Then
//TO DO
Else
EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Failure
// TODO
End If
End Sub
hope it helps someone :)
There are some missing codes from the answer above. The code of the class appdata is missing.These code is error without declaring first the tmpObj in the class AppData. Dim tmpObj As New AppData
tmpObj.No = rdr("No").ToString()
tmpObj.Template = templa8
FPList.Add(tmpObj)