I have such a code that tries to save some informations to database but my datacontext cannot be created. And it gives such an exception “Object reference not set to an instance of an object.” When i debugged, it jumps form “DataContext1 db = new DataContext1();” line to catch block and gives that exception. Is there any solution to this?
public class AuthorPaperDetails
{
public void SaveAuthorPaperDetails(string pTitle, string confMakerId,
string additionalPaperTitle,string mainAuthor,
int regFeeForFirstAuthor,int regFeeForAdditionalPaper, int RegFeeForCoAuthors)
{
try
{
DataContext1 db = new DataContext1();
AuthorPaperDetail authorPaperDetail = new AuthorPaperDetail();
authorPaperDetail.paper_title = pTitle;
authorPaperDetail.conference_maker_id = confMakerId;
authorPaperDetail.additional_paper_title = additionalPaperTitle;
authorPaperDetail.areYouMainAuthor = mainAuthor;
authorPaperDetail.feeForFirstAuthorPaper = regFeeForFirstAuthor;
authorPaperDetail.feeForAdditionalPaper = regFeeForAdditionalPaper;
authorPaperDetail.feeForParticipCoAuthors = RegFeeForCoAuthors;
db.AuthorPaperDetails.InsertOnSubmit(authorPaperDetail);
db.SubmitChanges();
}
catch (Exception)
{
}
}
}
Did you not save the connection information when you created the dbml or do you need to pass the connection information into the DataContext like so: