Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i developed an application with an activation, which worked well on my system but when i installed it on my client pc it show me this error

Unhandled exception has occured in your application. if you click continue the application will ignores this error and attempt to continue if you click quit the application will close immediately.

Object reference not set to an instance of an object.


Application Code
Imports System.Data.OleDb
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class dbbillz

    Private Sub txtdisplaydetails_TextChanged(sender As Object, e As EventArgs) Handles txtdisplaydetails.TextChanged
        If txtdisplaydetails.Text = "Enter A Name" Then
            txtdisplaydetails.Text = ""
        End If
    End Sub
    Private Sub TextBox_Validate(sender As Object, e As EventArgs) Handles txtdisplaydetails.TextChanged
        If Not String.IsNullOrWhiteSpace(txtdisplaydetails.Text) Then btqmatesearch.Enabled = True
    End Sub

    Private Sub btqmatesearch_Click(sender As Object, e As EventArgs) Handles btqmatesearch.Click
        Dim rpt As New CrystalReport2
        Dim searchString As String
        searchString = txtdisplaydetails.Text.Trim().ToLower()
        estimatingbilldisplay.ReportSource = Nothing
        If (searchString.Equals("")) Then
            MessageBox.Show("Please enter some search string to print report.", "Empty value", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return
        End If

        Dim DBCon As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & _
                                     "Data Source=estimate.accdb;")
        estimatingbilldisplay.Enabled = True
        Dim tblDataEstimate As New DataTable
        Dim tblEstimateWk As New DataTable
        Dim tblClients As New DataTable

        Dim cmd As New OleDbCommand()
        cmd.Connection = DBCon
        Dim da As New OleDbDataAdapter(cmd)

        cmd.CommandText = "select * from tblClients where name='" + searchString + "'"
        da.Fill(tblClients)

        cmd.CommandText = "select * from tblDataEstimate where name='" + searchString + "'"
        da.Fill(tblDataEstimate)

        cmd.CommandText = "select * from tblEstimateWk where name='" + searchString + "'"
        da.Fill(tblEstimateWk)

        If (tblClients.Rows.Count = 0) Then
            MessageBox.Show("No records could be found matching your search criteria, please retry with possible matcing string", "No Records Found", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        End If
        rpt.Database.Tables("tblClients").SetDataSource(tblClients)
        rpt.Database.Tables("tblDataEstimate").SetDataSource(tblDataEstimate)
        rpt.Database.Tables("tblEstimateWk").SetDataSource(tblEstimateWk)
        estimatingbilldisplay.ReportSource = rpt
        estimatingbilldisplay.Refresh()
        estimatingbilldisplay.RefreshReport()
    End Sub

    Private Sub dbbillz_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If (Not IsApplicationActivated()) Then
            Me.Enabled = False
            Dim f = New frmActivation()
            f.ShowDialog()
            If (IsApplicationActivated()) Then
                Me.Enabled = True            
            End If
        End If
    End Sub

    Private Function IsApplicationActivated() As Boolean
        Try
            Dim Status = CryptoEngine.Decrypt(My.Settings.Activated.ToString(), SharedVars.salt)
            If (Convert.ToBoolean(Status)) Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try
    End Function
End Class


Activation Code

Public Class frmActivation

    Private Sub btnActivate_Click(sender As Object, e As EventArgs) Handles btnActivate.Click
        If (Not String.IsNullOrEmpty(Me.txtKey.Text.Trim())) Then
            Dim KeyCode As Long = -1
            KeyCode = Long.Parse(txtKey.Text.Trim())
            If (KeyCode <> -1) Then
                If (Security.CheckKey(KeyCode)) Then
                    lblStatus.BackColor = Color.White
                    lblStatus.ForeColor = Color.Green
                    lblStatus.Text = "Application Activated."
                    My.Settings.Activated = CryptoEngine.Encrypt("True", SharedVars.salt)
                    My.Settings.Save()
                    Me.Close()
                Else
                    lblStatus.BackColor = Color.White
                    lblStatus.ForeColor = Color.Red
                    lblStatus.Text = "Incorrect Activation Key, Please Try Again."
                End If
            Else
                lblStatus.Text = "Invalid Character Entered, Please Try Again."
            End If
        End If
    End Sub

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click

    End Sub

    Private Sub txtKey_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtKey.KeyPress
        If (Not Char.IsControl(e.KeyChar) And Not Char.IsDigit(e.KeyChar)) Then
            e.Handled = True
        End If
    End Sub

    Private Sub frmActivation_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.lblCode.Text += Environment.NewLine + Security.GetSerailNo().ToString()
    End Sub
End Class


What I have tried:

have tried to debug and rebuild
Posted
Updated 26-Jan-21 5:49am
Comments
Richard Deeming 26-Jan-21 8:18am    
cmd.CommandText = "select * from tblClients where name='" + searchString + "'"

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

Put a breakpoint (red dot) in the margin before the place where the error occurs and use the debugger to inspect the value of variables by hovering over them with the mouse.
See: Tutorial: Debug Visual Basic code - Visual Studio | Microsoft Docs[^]
 
Share this answer
 
v2
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself.

Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which means that there is no instance of a class in the variable.
It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen. If you reach into the pocket and find there isn't a pen there, you can't sign your name on a piece of paper - and you will get very funny looks if you try! The empty pocket is giving you a null value (no pen here!) so you can't do anything that you would normally do once you retrieved your pen. Why is it empty? That's the question - it may be that you forgot to pick up your pen when you left the house this morning, or possibly you left the pen in the pocket of yesterday's shirt when you took it off last night.

We can't tell, because we weren't there, and even more importantly, we can't even see your shirt, much less what is in the pocket!

Back to computers, and you have done the same thing, somehow - and we can't see your code, much less run it and find out what contains null when it shouldn't.
But you can - and Visual Studio will help you here. Run your program in the debugger and when it fails, VS will show you the line it found the problem on. You can then start looking at the various parts of it to see what value is null and start looking back through your code to find out why. So put a breakpoint at the beginning of the method containing the error line, and run your program from the start again. This time, VS will stop before the error, and let you examine what is going on by stepping through the code looking at your values.

But we can't do that - we don't have your code, we don't know how to use it if we did have it, we don't have your data. So try it - and see how much information you can find out!
 
Share this answer
 
Comments
Bj Molo 26-Jan-21 10:28am    
The thing is working well on my own pc, but if i build the the application, thats when it shows that error
OriginalGriff 26-Jan-21 10:46am    
So you need to start looking at the new target machine: we can't do that for you!

Start by narrowing down where the problem is: if you can't use a debugger on it, then you will have to go "old school" and add logging code to find out the area in which it fails.
When you have that, you start adding more logging to narrow that down, and continue this process until you have a good idea where it is failing. Then use logging to monitor the data you are working with, and compare that which what you expect.

We can't do any of that for you!
I solved the problem and which was the crystal report version on the client machine was not really the version i used..

Thank you everyone who contributed in solving the issue with me
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900