vb.net : DPFP.Error.SDKException: Verification Failure - mysql

I am having a problem with my fingerprint verification using vb.net 2010. I am not sure if what makes the error every time i verify the template from my mysql database. Below is the error message. I am using digital persona u.are.u 4000b as my fingerprint scanner.
and this is my code for verification:
DrawPicture(ConvertSampleToBitmap(Sample))
Dim features As DPFP.FeatureSet = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification)
conn.Open()
cmd.Connection = conn
cmd.CommandText = "Select * from emp_t"
dr = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read()
Dim MemStream As IO.MemoryStream
Dim fpBytes As Byte()
fpBytes = dr(2)
MemStream = New IO.MemoryStream(fpBytes)
Dim templa8 As DPFP.Template = New DPFP.Template()
templa8.DeSerialize(MemStream)
Me.Template = templa8
' Check quality of the sample and start verification if it's good
If Not features Is Nothing Then
' Compare the feature set with our template
Dim result As DPFP.Verification.Verification.Result = New DPFP.Verification.Verification.Result()
Try
Verificator.Verify(features, templa8, result)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
If result.Verified Then
MessageBox.Show("Verified")
Exit Sub
Else
MessageBox.Show("The fingerprint was NOT VERIFIED!")
End If
Else
MessageBox.Show("Fingerprint sample is not established!")
End If
End While
Else
MessageBox.Show("No record found!")
End If
conn.Close()
I been struggling for months in searching for the solution on my problem. To anyone who can share there thoughts and extends help will be much much appreciated... Thank you...

Related

My code was working earlier until I added error messages for checking if CapNum is empty or already existed on the database

Dim cmd As MySqlCommand
cmd = con.CreateCommand
con.Open()
Try
If String.IsNullOrEmpty(capNum.Text.ToString()) Then
MessageBox.Show("Please fill up the Capstone Number to proceed.")
Else
Dim theQuery As String = "select * from listofcapstone where caps_Number like '%" & capNum.Text & "%'"
Dim cmd1 As MySqlCommand = New MySqlCommand(theQuery, con)
Dim reader As MySqlDataReader = cmd1.ExecuteReader()
If reader.HasRows Then
reader.Close()
MessageBox.Show("There's already an existing data with this Capstone Number!")
Else
cmd.CommandText = "insert into listofcapstone(caps_Number, thesis_Title, ictdu_entNumber, year, course)values(#caps_Number, #thesis_Title, #ictdu_entNumber, #year, #course)"
cmd.Parameters.AddWithValue("#caps_Number", capNum.Text)
cmd.Parameters.AddWithValue("#thesis_Title", title.Text)
cmd.Parameters.AddWithValue("#ictdu_entNumber", ictduCapNum.Text)
cmd.Parameters.AddWithValue("#year", yr.Text)
cmd.Parameters.AddWithValue("#course", course.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("SUCCESSFULLY ADDED!")
capNum.Clear()
title.Clear()
ictduCapNum.Clear()
course.Clear()
yr.SelectedIndex = -1
End If
End If
Catch ex As Exception
MessageBox.Show("Connection Lost!!")
Me.Close()
End Try
con.Close()
I found the problem on my code..i tried to remove try and catch to see which part of the code wasnt used properly and receive the "MySqlException was unhandled" error message..then put a reader on the else part
Dim theQuery As String = "select * from listofcapstone where caps_Number like '%" & capNum.Text & "%'"
Dim cmd1 As MySqlCommand = New MySqlCommand(theQuery, con)
Dim reader As MySqlDataReader = cmd1.ExecuteReader()
If reader.HasRows Then
reader.Close()
MessageBox.Show("There's already an existing data with this Capstone Number!")
Else
reader.Close() 'Where I put the reader.'
cmd.CommandText = "insert into listofcapstone(caps_Number, thesis_Title, ictdu_entNumber, year, course)values(#caps_Number, #thesis_Title, #ictdu_entNumber, #year, #course)"
cmd.Parameters.AddWithValue("#caps_Number", capNum.Text)
cmd.Parameters.AddWithValue("#thesis_Title", title.Text)
I suggest you use parameterized queries instead of concatenating your queries like you're doing with that SELECT statement in order to mitigate SQL Injection attacks. You can read this and this to learn more about it.
You can also use the Using statement that will dispose of any object that has implemented the IDisposable interface such as the MySqlConnection and MySqlCommand objects. From the documentation:
Sometimes your code requires an unmanaged resource, such as a file
handle, a COM wrapper, or a SQL connection. A Using block guarantees
the disposal of one or more such resources when your code is finished
with them. This makes them available for other code to use.
You can also break down into separate Sub routines the queries for retrieving a record and inserting a new one. I put together a basic example showing what I discussed:
Imports System
Imports System.Data
Imports MySql.Data
Imports MySql.Data.MySqlClient
Namespace MySqlCmdExample
Class Program
Private Shared Sub Main(args As String())
Dim dataProvider As New AlbumDataProvider()
Try
If dataProvider.AlbumExists("Album_Five") Then
Console.WriteLine("Album exists...")
Return
End If
Console.WriteLine("Adding new album...")
dataProvider.AddAlbum(3, "Album_Five")
Catch ex As MySqlException
Console.WriteLine([String].Format("Oops, an error occurred: {0}", ex.Message))
End Try
End Sub
End Class
Public Class AlbumDataProvider
Private connectionString As String = "server=localhost;user=<your_username>;database=stack_overflow;port=3306;password=<your_password>"
Public Sub New()
End Sub
Public Function AlbumExists(name As String) As Boolean
Dim found As Boolean = False
Using conn As New MySqlConnection(connectionString)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim cmd As New MySqlCommand("SELECT * FROM Album WHERE `Name` = #albumName", conn)
cmd.Parameters.AddWithValue("#albumName", name)
Using reader As MySqlDataReader = cmd.ExecuteReader()
found = reader.HasRows
End Using
End Using
Return found
End Function
Public Sub AddAlbum(ownerId As Integer, name As String)
Using conn As New MySqlConnection(connectionString)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim cmd As New MySqlCommand("INSERT INTO Album(OwnerId, Name) VALUES(#ownerId, #albumName)", conn)
cmd.Parameters.AddWithValue("#ownerId", ownerId)
cmd.Parameters.AddWithValue("#albumName", name)
cmd.ExecuteNonQuery()
End Using
End Sub
End Class
End Namespace

vb.net sql date index was outside the bounds of the array

This code seems strange for me because it doesn't have arrays yet it says "index was outside the bounds of the array". Anyways, here's my code
con.Open()
'sql problem
Try
sql ="SELECT trans_event FROM tbl_transdetail WHERE trans_fromdate = #2015-08-16#"
com = New MySqlCommand(sql, con)
reader = com.ExecuteReader
If reader.HasRows Then
While reader.Read()
Dim ev = reader.GetString("trans_event")
Dim lo = reader.GetString("trans_location")
Dim frmd As Date = reader.GetString("trans_fromdate")
Dim frmt = reader.GetString("trans_fromtime")
Dim tod As Date = reader.GetString("trans_todate")
Dim tot = reader.GetString("trans_totime")
.Items.Add(New ListViewItem({ev, lo, frmd, frmt, tod, tot}))
End While
Else
Dim i = reader.FieldCount
End If
reader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
where the error is shockingly on the sql statement..
any help will greatly appreciated... thanks...

"Object Reference not Set to an Instance of an Object" when trying to read from MySQL

I've been trying to finish up this assignment, due tomorrow, since we got it a few hours ago. Our class was never really taught VB, we just did a brief overview of the very basics of the language and then were told to go copy the code on our assignments and fill in the rest.
At the moment I'm stuck with an error, which you can see in the title, which is preventing me from finishing up the rest of my program. I've looked around for solutions, but they haven't been very helpful due to my complete lack of knowledge of VB and Visual Studio. (I normally code in Java with Eclipse.)
If anyone can explain what's causing this error and how to avoid it in the future that would help a lot. Thanks for any replies.
Imports System.Data
Imports MySql.Data.MySqlClient
Public Class inventoryUpdate_form
Dim quantity As Integer
Dim quantityList As List(Of Integer)
Dim isbn As Integer
Dim isbnList As List(Of Integer)
Public Sub refreshData(first As Boolean)
'Establish connection to the DB.
Dim connection As MySqlConnection = New MySqlConnection
connection.ConnectionString = "server=ERASED;port=ERASED;user id=ERASED;password=ERASED;database=ERASED"
Try
connection.Open()
' Clear the quantity and isbn lists before adding new data.
Try
quantityList.Clear()
Catch e As NullReferenceException
End Try
Try
isbnList.Clear()
Catch e As NullReferenceException
End Try
' Build a query
Dim query As String
query = "SELECT book.title, inventory.quantity, book.ISBN FROM book JOIN inventory ON book.ISBN = inventory.ISBN JOIN store ON inventory.store_id = store.store_id WHERE store.city = 'Fredericton' AND inventory.quantity > 0 ORDER BY book.title ASC"
' Run the query.
Dim cmd As New MySqlCommand(query, connection)
Try
Dim dataReader As MySqlDataReader = cmd.ExecuteReader
Dim title As String
While dataReader.Read()
title = dataReader("title")
ComboBox1.Items.Add(title)
quantity = dataReader("quantity")
quantityList.Add(quantity)
isbn = dataReader("ISBN")
isbnList.Add(isbn)
End While
dataReader.Close()
Catch e As Exception
MessageBox.Show("Data Reader error: " & e.Message)
End Try
Catch e As MySqlException
' If an error occurs while connecting to the DB then show the error message.
MessageBox.Show("Cannot connect to the database: " & e.Message)
Finally
' Close and dispose of the connection to the DB.
connection.Close()
connection.Dispose()
End Try
End Sub
Private Sub inventoryUpdate_form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
refreshData(True)
End Sub
End Class
The error is being shown on this try-catch:
' Run the query.
Dim cmd As New MySqlCommand(query, connection)
Try
Dim dataReader As MySqlDataReader = cmd.ExecuteReader
Dim title As String
While dataReader.Read()
title = dataReader("title")
ComboBox1.Items.Add(title)
quantity = dataReader("quantity")
quantityList.Add(quantity)
isbn = dataReader("ISBN")
isbnList.Add(isbn)
End While
dataReader.Close()
Catch e As Exception
MessageBox.Show("Data Reader error: " & e.Message)
End Try
That's all I know about the error. I've been looking around for some sort of stack trace, but all I've found is this unhelpful block of text which is a bit too messy to paste here so here you go: http://pastebin.com/nGqw6V8R
quantityList and isbnList are null. Use New to initialize them...
Dim quantityList As New List(Of Integer)
Dim isbnList As New List(Of Integer)
I'm not sure but if you are getting a "Object Reference..." error in the try catch block you mention it could be the sibList is not inizialized
Try add in the declaration of the variable this:
Dim isbnList As New List(Of Integer)

Host x is not allowed to connect to this mysql server

I am trying to make a simple registration & activation system using my mysql server and vb.net and I am using the code below:
Imports MySql.Data.MySqlClient
Public Class ActivateMe
Dim MysqlConn As MySqlConnection
Dim myAdapter As New MySqlDataAdapter
Dim myData As MySqlDataReader
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MysqlConn = New MySqlConnection()
Try
MysqlConn.Open()
Dim checkUsername As String = "SELECT COUNT(*) FROM users WHERE verif=#p1 and username=#p2"
Dim insertData As String = "INSERT INTO users(hasVerif) VALUES(#p3)"
Using MysqlConn = New MySqlConnection(mysqlconntxt4reg)
Using myCommand = New MySqlCommand(checkUsername, MysqlConn)
MysqlConn.Open()
myCommand.Parameters.AddWithValue("#p1", TextBox1.Text)
myCommand.Parameters.AddWithValue("#p2", currentRegUser)
Dim result = myCommand.ExecuteScalar()
If result IsNot Nothing AndAlso Convert.ToInt32(result) > 0 Then
Using myCommand2 = New MySqlCommand(insertData, MysqlConn)
myCommand.Parameters.AddWithValue("#p3", 1)
myCommand2.ExecuteNonQuery()
MsgBox("Successfully Activated! You May Now Login!", MsgBoxStyle.Information, "Success")
Me.Close()
End Using
Else
MsgBox("Invalid Activation Code", MsgBoxStyle.Critical, "Error")
End If
End Using
End Using
MysqlConn.Close()
Catch myerror As MySqlException
MessageBox.Show("Cannot connect to database: " & vbNewLine & vbNewLine & myerror.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
End Class
The program sends the activation code to the email successfully and uploads the activation code to the database for checking but when I am on the activation form and enter the code, it says:
Host (my pc name) is not allowed to connect to this mysql server
In the different forms, the server accepts the connection and allows access to the database so I don't see why it would be different here...
Please send me help!
Thanks
rodit
I'm not very familiar with MySQL under .NET but I believe you do something a bit odd here. First you open a connection without a connection string (I assume that uses default parameters)
MysqlConn = New MySqlConnection()
Try
MysqlConn.Open()
and then you open another connection using an explicit string
Using MysqlConn = New MySqlConnection(mysqlconntxt4reg)
Using myCommand = New MySqlCommand(checkUsername, MysqlConn)
MysqlConn.Open()
Notice it's the same MysqlConn variable (with different objects).
So the MySqlException you're catching could be coming from any one of them. You can use that exception to find out which of the open calls actually triggered the exception (I assume it's first one).
You should probably also cleanup code and keep only one open call.
Andrei

data reader in vb.net

Please help, how do I make a while loop equivalent of this for loop. So that I could read from one row in the table of mysql database and display it on the combobox in vb.net.
I use this code, but its definitely not useful if there are 3 or more items that are added in the row:
Dim i As Integer
Dim rdr As Odbc.OdbcDataReader
rdr = con.readfrom_drug_type_table()
For i = 0 To 1
If rdr.HasRows = True Then
rdr.Read()
ComboBox2.Items.Add(rdr("Drug_type"))
End If
Next i
I want to read all the data from that the Drug_type row
Please help, thanks
If you want to read only first row than just use
If rdr.Read() Then
ComboBox2.Items.Add(rdr("Drug_type"))
End If
Update
Try
myConnection = New SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")
'you need to provide password for sql server
myConnection.Open()
myCommand = New SqlCommand("Select * from discounts", myConnection)
dr = myCommand.ExecuteReader
While dr.Read()
WriteLine(dr(0))
WriteLine(dr(1))
WriteLine(dr(2))
WriteLine(dr(3))
WriteLine(dr(4))
' writing to console
End While
Catch
End Try
dr.Close()
myConnection.Close()
#pranay
You don't need the nested loops.
Try
myConnection = New SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")
myConnection.Open()
myCommand = New SqlCommand("Select * from discounts", myConnection)
dr = myCommand.ExecuteReader()
While dr.Read()
WriteLine(dr(0))
WriteLine(dr(1))
WriteLine(dr(2))
WriteLine(dr(3))
WriteLine(dr(4))
End While
dr.Close()
Finally
myConnection.Close()
End Try