Solved

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

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

Industry Leaders: 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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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