Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can you help me..
i get error for that code


"System.NullReferenceException: Object reference not set to an instance of an object."

this is the code:

VB
Sub Activation()
           Dim activationKey As String = Date.Now.Millisecond * Date.Now.Second * 3 * Year(Now) + Date.Now.Day * 77 'Generates Activation Key
           Try
               strCon = System.Configuration.ConfigurationManager.AppSettings("ConnectX").ToString()
           strQry = "Insert INTO tActivation (sUsername,ActivationCode,ActivationStatus,DateRegistered,DateActivated,AccountEmail) Values('" & userID & "','" & activationKey & "','" & 0 & "','" & Now & "','" & Now & "','" & txtEmail.Text & "')"
               cn = New SqlConnection(strCon)
               cn.Open()
               Com = New SqlCommand(strQry, cn)
               Com.ExecuteNonQuery()
               Com.Dispose()
               cn.Close()
               SendToMail(activationKey) 'Calls a Procedure to send the key using SMTP server


           Catch ex As Exception

       End Try
       End Sub


error on code "Com.Dispose()"

i hope you can help me.. thanks..
Posted
Comments
Ganesan Natarajan 20-Mar-12 2:48am    
what is purpose of Com.Dispose(), actullay not required... .net will take of it..
chandanadhikari 20-Mar-12 11:38am    
hi,
this generally happens when you are trying to use an object that does not exist(was not formed or got destroyed before you referred to it).debugging will show you the exact line where this is happening.actually this will be the place where you are trying to use the object. your object might be getting disposed before this line is getting executed.

Are you sure it happened really there?
Where did you declare the variables cn and Com ("Dim cn as ....")? Are they static? If they were declared locally in the function, that error can not happen at that position.
 
Share this answer
 
It does seem odd that it's happening at the .Dispose location. Perhaps it's because the connection is still open? You may want to try to close the connection first. Move cn.Close() ahead of it.
 
Share this answer
 
v2
i hope plz wanna help me.. thanks..
 
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