0

I have a static field in a non static class.

public class DBtools
{
     public static string ConString ="XXXXXXXXX";
}

This field is assigned to property in the code.

SqlDataSource1.ConnectionString = DBtools.ConString;

But after i run this app I'm getting a error:

Object reference not set to an instance of an object

How come this is happening? It's a static field.

C-Pound Guru
  • 14,819
  • 6
  • 45
  • 65
user137348
  • 9,610
  • 17
  • 62
  • 88

3 Answers3

3

The SqlDataSource1 object has not been initialized.

2

You have a debugger in front of you. Put a break point on that line, and when it stops investigate all the fields/variables/etc involved. It sounds like however SqlDataSource1 is defined, it is currently null.

Marc Gravell
  • 927,783
  • 236
  • 2,422
  • 2,784
1

Maybe the error is referring to SqlDataSource1 being null?

Christian Hayter
  • 29,333
  • 6
  • 65
  • 96