Solved

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

Posted on 2009-04-14
4
305 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now