Let's say I have a method like this:
public class MyDataAccess
{
public static StudentDataTable GetStudentRecords(int schoolID)
{
var ta = new StudentTableAdapter();
using (ta.Connection = new SqlConnection(GetCS()))
{
var result = ta.GetStudentRecords(schoolID);
return result;
}
}
}
If this method is accessed 1,000 times at a single time, using a console app or any other means, would there be any chance of it returning records for one school's student to another school?
e.g.
var records1 = GetStudentRecords(1);
.....
var records1000 = GetStudentRecords(1000);
Is there any chance of the records1
variable getting records of schoolID = 1
mixed with records from records1000
, even if they calls come from their own threads?
Also what is going to happen if I change this class to static as well?
My understanding at this point
1) Yes, I understand what a class is
2) Yes, I know static classes don't need required instances to be used
3) I know simple static code should be there, for example converting datatypes.
But what I am confused with is:
What happens when there is a single, static class and there are a million objects trying to access the same object in STACK
especially when it's a dataAccess
class, or a class which accesses activeDirectory
objects.
I had a chat in the programmers SE chat room. They didn't say it explicitly, but I got the impression to never use static classes for querying e.g. sql, active directory, etc.. And that static classes should be limited to simple static code only - no querying.