I just downloaded and installed the starter kit. Then I attached the database to my SQL server and commented the classifiedsConnection in the connection strings in web.config and added a new classifiedsConnection with the connection infor to the restored
database. Then when I ran the web site, it opened the site without any issues. When I click on the login link, it gave me the following error.
Object reference not set to an instance of an object.
Now even when I stop and restart the site in VS2005 it keeps giving me the above error at the following line of code.
Line 23: Protected Sub PasswordRecovery_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles PasswordRecovery.Init
Line 24: Dim s As SiteSettings = SiteSettings.GetSharedSettings()
Line 25: PasswordRecovery.MailDefinition.From = s.SiteEmailFromField
Line 26: End Sub
Line 27:
When I checked the contents in the debug mode, I do see values for variable s, but it keeps giving me the error. Also in debug mode it stops at the above line and displays "Use the New keywork to create an object instance"
I am not sure how to fix this. I am using SQL 2005 with VS 2005.
MailDefinition is a class. You need to instantiate it before working with it. So I suspect that MailDefinition is null and you're trying to access the From property on a null object.
But when I checked the value it was empty, even though variable s has something, the error is coming because of that variable and I cannot use new keywork there.
But when I checked the value it was empty, even though variable s has something, the error is coming because of that variable and I cannot use new keywork there.
You seem to be hung up on the s variable. Read what I posted before carefully. And to confirm what I said, or prove me wrong, put a breakpoint and hover over MailDefinition. I'll bet, a shiny penny, that it's null.
That error comes when you perform any operation on a object which is null. For example suppose if you are doing obj.ToString() and if obj is null then that error will come , so please debug your code and debug line by line and see where it is causing that
error and see on that line an object on which you would be performing any operation will be set as null.
I moved the enrite site to another pc that has SQL express installed and everything is working fine on that pc. Not sure why it's not working on my other pc with a remote SQL database. But for now I consider this as resolved.
SQL Server by default wont allow "Remote Connections" off its internal network.
If you are using a hosting provider it is unlikely that you can change this setting because of vulnerability of attacks that can corrupt there systems or your data, how ever there are some providers who have taken extra measures to protect against such attacks
and may have the option to allow remote connections.
If it is a functionality you NEED then contacting your provider is my recommendation.
Classifieds Starter Kit
Trading Center is a Continuation of the Classifieds Starter Kit onCode Plex.
coolvaas1
Participant
938 Points
435 Posts
Object reference not set to an instance of an object.
May 07, 2010 06:31 PM|LINK
I just downloaded and installed the starter kit. Then I attached the database to my SQL server and commented the classifiedsConnection in the connection strings in web.config and added a new classifiedsConnection with the connection infor to the restored database. Then when I ran the web site, it opened the site without any issues. When I click on the login link, it gave me the following error.
Object reference not set to an instance of an object.
Now even when I stop and restart the site in VS2005 it keeps giving me the above error at the following line of code.
Line 23: Protected Sub PasswordRecovery_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles PasswordRecovery.Init
Line 24: Dim s As SiteSettings = SiteSettings.GetSharedSettings()
Line 25: PasswordRecovery.MailDefinition.From = s.SiteEmailFromField
Line 26: End Sub
Line 27:
When I checked the contents in the debug mode, I do see values for variable s, but it keeps giving me the error. Also in debug mode it stops at the above line and displays "Use the New keywork to create an object instance"
I am not sure how to fix this. I am using SQL 2005 with VS 2005.
Any help is greatly appreciated.
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: Object reference not set to an instance of an object.
May 07, 2010 07:34 PM|LINK
MailDefinition is a class. You need to instantiate it before working with it. So I suspect that MailDefinition is null and you're trying to access the From property on a null object.
coolvaas1
Participant
938 Points
435 Posts
Re: Object reference not set to an instance of an object.
May 07, 2010 07:37 PM|LINK
But when I checked the value it was empty, even though variable s has something, the error is coming because of that variable and I cannot use new keywork there.
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: Object reference not set to an instance of an object.
May 07, 2010 07:42 PM|LINK
You seem to be hung up on the s variable. Read what I posted before carefully. And to confirm what I said, or prove me wrong, put a breakpoint and hover over MailDefinition. I'll bet, a shiny penny, that it's null.
raghav_khung...
All-Star
32835 Points
5563 Posts
MVP
Re: Object reference not set to an instance of an object.
May 07, 2010 07:47 PM|LINK
Going with above poster,
That error comes when you perform any operation on a object which is null. For example suppose if you are doing obj.ToString() and if obj is null then that error will come , so please debug your code and debug line by line and see where it is causing that error and see on that line an object on which you would be performing any operation will be set as null.
manorfarm
Member
114 Points
50 Posts
Re: Object reference not set to an instance of an object.
May 08, 2010 05:21 PM|LINK
Have you run ASPNet Configuration from the website tab in visual web developer
coolvaas1
Participant
938 Points
435 Posts
Re: Object reference not set to an instance of an object.
May 10, 2010 02:34 PM|LINK
Ok, I put a breakpoint at PasswordRecovery.MailDefinition.From = s.SiteEmailFromField
And the PasswordRecovery.MailDefinition.From value is blank
When I check the value in s.SiteEmailFromField, I get / see the 'Referenced object has a value of 'Nothing''
So to confirm it, at the breakpoint I entered the following.
PasswordRecovery.MailDefinition.From ="test"
And the above statement works (no errors). So I don't believe the error is with MailDefinition class.
coolvaas1
Participant
938 Points
435 Posts
Re: Object reference not set to an instance of an object.
May 10, 2010 06:41 PM|LINK
I moved the enrite site to another pc that has SQL express installed and everything is working fine on that pc. Not sure why it's not working on my other pc with a remote SQL database. But for now I consider this as resolved.
Thanks for all your feedbacks.
Spider Maste...
Participant
1664 Points
483 Posts
Re: Object reference not set to an instance of an object.
May 10, 2010 11:42 PM|LINK
SQL Server by default wont allow "Remote Connections" off its internal network.
If you are using a hosting provider it is unlikely that you can change this setting because of vulnerability of attacks that can corrupt there systems or your data, how ever there are some providers who have taken extra measures to protect against such attacks and may have the option to allow remote connections.
If it is a functionality you NEED then contacting your provider is my recommendation.
Trading Center is a Continuation of the Classifieds Starter Kit onCode Plex.
coolvaas1
Participant
938 Points
435 Posts
Re: Object reference not set to an instance of an object.
May 11, 2010 03:03 PM|LINK
Actually I have other web applications that connect to the SQL server. So the remote connections are on.