TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
dc
NA
663
0
C# constructor "Object reference not set to an instance of an object."
Nov 15 2012 1:32 PM
In a C# 2008 application I am getting the error message "Object reference not set to an instance of an object."
The line of code that is causing this to occur is the following:
public eDataContext() :
base(ConfigurationManager.ConnectionStrings["DEVConnectionString"].ConnectionString, mappingSource).
I have a reference set to system.configuration and I have a using System.Configuration.
Below you will find my app.config file and code that I am referring to:
app.config file code:
<connectionStrings>
<add name="esample.Properties.Settings.RPCSS_DEVConnectionString"
connectionString="Data Source=DEV2;Initial Catalog=DEV;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
The actual code:
namespace eclient
{
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;
using System.Configuration;
public partial class eDataContext : System.Data.Linq.DataContext
{
[System.Data.Linq.Mapping.DatabaseAttribute(Name = "DEV")]
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
public eDataContext() :
base(ConfigurationManager.ConnectionStrings["DEVConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public eDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public eDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public eDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public eDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
Thus can you tell me how to fix this code?
Reply
Answers (
20
)
Include ("header.aspx") in asp.net like php
When will use threading in c#??? Which scenario uses threading in c# application?