Solved

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

Posted on 2009-04-14
4
315 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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