.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Null Reference Ex

Posted By: Aamrapali Tamgadge     Posted Date: January 14, 2011    Points:2   Category :ASP.Net
Hi.Wen i host my website i got the error please anyone can suggest me what should i do for solving this please reply if anyone knows its argent.


Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
BaseDB.ExecuteScalar(DbCommand dbCommand) +91
_Default.ShowTestimonial() +34
_Default.Page_Load(Object sender, EventArgs e) +32
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4206; ASP.NET Version:2.0.50727.4205

Responses
Author: Manas Patnaik             
Posted Date: January 14, 2011     Points: 5   

Simply this line is throwing error

BaseDB.ExecuteScalar(DbCommand dbCommand) 


Can you please post the page load event code and the link where you have hosted ?

Manas Patnaik
http://manaspatnaik.com/blog
Author: Aamrapali Tamgadge             
Posted Date: January 14, 2011     Points: 5   

Below i hv given my page load event code and link http://www.mcaentrance.com/


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
ShowNotice();
ShowTestimonial();
ShowThought();
}
catch { }
}
}



//and this is my ShowTestimonial() method
private void ShowTestimonial()
{
DbCommand dbcom = BaseDB.CreatestrCommand();
dbcom.CommandText = "Select top(1) Message from Testimonial where Status='True' order by Id desc";
string tl = BaseDB.ExecuteScalar(dbcom);
string ss = Regex.Replace(tl, @"<(.|\n)*?>", string.Empty);
if (ss.Length > 480)
{
lblTestiml.Text = ss.Remove(480);
}
else
{
lblTestiml.Text = ss;
}
}



//This Execute Scalar method
public static string ExecuteScalar(DbCommand dbCommand)
{
string returnValue = "";
try
{
dbCommand.Connection.Open();
returnValue = dbCommand.ExecuteScalar().ToString();

}
catch (Exception exc)
{

throw exc;
}
finally
{
dbCommand.Connection.Close();
}

return returnValue;

}

Software Programmer At OTIS ISRC
Author: Manas Patnaik             
Posted Date: January 14, 2011     Points: 5   

dbCommand.Connection.Open();


Where you have Assigned The Connection to the Command ?
Also Write the Detailed Error Messege Using Response.Write in the Catch Block.

try
{
if(dbCommand.Connection != null)
{
dbCommand.Connection.Open();
returnValue = dbCommand.ExecuteScalar().ToString();
}

}


May be also Check With this Line
returnValue = dbCommand.ExecuteScalar().ToString();


Use Convert.ToString instead of above line.

Manas Patnaik
http://manaspatnaik.com/blog
Author: Chandranshu Awasthi             
Posted Date: January 17, 2011     Points: 5   

Hardwork n Determination d only key to success

Author: Aamrapali Tamgadge             
Posted Date: January 17, 2011     Points: 5   

Hi,Manas..
I have Written my connection string in web.config file

and in the same base db cls i use the blw to get the connection string

public Connection()
{
connect = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

}
..
Actualy Problem is dat this website is properly working in local machine
and all the operation related to dis are working correctly i have checked it all through brkpts..
But I havent Any Access Permission for d server n i hv to complete this task ..please suggest me what shoud i do now.

Software Programmer At OTIS ISRC
Author: Aamrapali Tamgadge             
Posted Date: January 17, 2011     Points: 5   

Hi..Manas I Got d Solution for this topic..
Actualy der is do data in testimonial table on server..m returning value..
so Simply i fire the insert query in dat table..

Thanks for your cooperation..

Software Programmer At OTIS ISRC


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend