?
Solved

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

Posted on 2009-04-14
4
Medium Priority
?
320 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 2000 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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