Hi there,
That's because you only declared the private SqlConnection as static. You should change the public property con2 to static as well.
However, I am not so sure if this is a wise design decision. With this design, all classes that use AA (nice name, BTW ;) ) share *one* global connection object. I think this will result in poor performance, as all requests are queued up. If one of the classes that use AA open a DataReader, the connection is blocked until you close the reader.
A better approach is to have a public connection
string that other classes can use. Alternatively, create a class that abstracts the data access code for you. e.g.:
Code:
public class MyDataClass()
{
public DataSet ExecuteSQL(string sql)
{
string connectionString = AA.ConnectionString;
// Create connection here with the ConnectionString from AA
// return a dataset constructed with the connection created in
// this method
}
}
If you're trying to abstract your data access code from your UI or business layer, take a look here:
http://msdn.microsoft.com/library/de...ml/daab-rm.asp
This is the Data Access Application Block from Microsoft and demonstrates a nice (and ready to use) way to implement a data access class.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to:
Pumpkin by
Tricky (Track 5 from the album:
Maxinquaye)