Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Try
            conn.ConnectionString = My.Settings.Database1ConnectionString
            conn.Open()

            cmd.Connection = conn
            cmd.CommandText = "SELECT passid FROM tblogin Where user=@user"
            cmd.Parameters.AddWithValue("@user", txtcod_ut.Text)
            passid = cmd.ExecuteScalar

            conn.Close()
  If suportelogin.GeraHash(txtpass.Text).Equals(passid) Then
                My.Forms.Página_Principal.ShowDialog()
                Me.Hide()
            Else
                MessageBox.Show("Erro!.", "Verifique de novo o código do utilizador e a palavra-passe", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                'focus- quando for precionado o botão "enter" do teclado, ele vai ativar esse controle como Ok
                txtpass.Focus()
            End If
        Catch ex As Exception

            MessageBox.Show("Erro ao efetuar a conexão com a base de dados :" + ex.Message)
            conn.Dispose()

        End Try
Posted
Updated 19-Apr-13 1:57am
v2
Comments
Orcun Iyigun 19-Apr-13 7:47am    
Debug your code and tell us which line it is throwing the exception?
Nillo123 19-Apr-13 7:57am    
conn.ConnectionString = My.Settings.Database1ConnectionString

conn returns nothing
i checked if is null..and nothing happen
Aarti Meswania 19-Apr-13 7:48am    
in which line you get this exception?
ZurdoDev 19-Apr-13 7:48am    
What line is it? The error is telling you that something you are trying to access has not been initialized or does not exist.
Nillo123 19-Apr-13 7:55am    
conn.ConnectionString = My.Settings.Database1ConnectionString

conn returns nothing

1 solution

Why do I get the error "Object reference not set to an instance of an object"?[^].

Quote:
conn.ConnectionString = My.Settings.Database1ConnectionString

conn returns nothing


It is NOT 'conn returns nothing', it is 'conn is nothing' instead. That means your conn variable does not contain a reference to a valid (Connection) object.
Probably you are using conn before its proper initialization code is called.
 
Share this answer
 
Comments
Nillo123 19-Apr-13 8:16am    
if i put the : 'conn.ConnectionString = My.Settings.Database1ConnectionString' in try my problems beggins on connDispose()
Try
conn.ConnectionString = My.Settings.Database1ConnectionString
conn.Open()

cmd.Connection = conn
.
.
.
conn.Dispose()

msg error : Object reference not set to an instance of an object...

if i remove 'conn.ConnectionString = My.Settings.Database1ConnectionString' from the try.. he gives me the error on beggining...like you said before..

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