Solved

c#, asp.net- using linq in .net 2.0

Posted on 2009-04-14
4
317 Views
Last Modified: 2012-05-06
Hi,
I am trying to code in .net 2.0 when I'm used to .net 3.0
I have linked the LinqBridge.dll but I'm still having troubles with establishing a link between my database and tha aspx code
I have the error:  System.NullReferenceException: Object reference not set to an instance of an object.
 for line:
 conn = new SqlConnection(ConfigurationManager.ConnectionStrings["std"].ConnectionString);

Should I still have the namespace using System.Linq; or something else now that i have the LinqBridge.dll?

Many thanks

public class DBConnect
{
 
    public static SqlConnection conn = null;
 
    public static void OpenConnection()
    {
        DBConnect.CloseConnection();
        if (conn == null)
        {
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["std"].ConnectionString);
        }
 
        conn.Open();
    }
 
    public static void CloseConnection()
    {
        if (conn != null)
            conn.Close();
    }

Open in new window

0
Comment
Question by:CharlieDev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24138361
The LINQ syntax is not supported in .NET 2.0, it's not use to even attempt to try it.

Your connection might be null if the SqlConnection doesn't succeed. Test it for being null, the way you are already doing in some places in your code.
0
 
LVL 39

Assisted Solution

by:abel
abel earned 500 total points
ID: 24138377
In addition, the error may also come from the connectionStrings dictionalry you are referring to. If it isn't there, it will return the same exception you just mentioned. Note that the dictionary is case sensitive.
0
 

Author Closing Comment

by:CharlieDev
ID: 31569901
Thanks,I was being stupid. In my haste I hadnt set up the connection to the DB in the webconfig!!! doh
0
 
LVL 39

Expert Comment

by:abel
ID: 24138551
> Thanks, In my haste I hadnt set up the connection to the DB in the webconfig!!!

no problem, glad you found it now ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question