Static method is safe to use for Data access layer methods

Posted by Ray.chayan under C# on 8/9/2010 | Views : 7554 | Status : [Member] | Replies : 2
if two different users access the same static member in the same application then is it transaction safe? I mean if we use static methods in data access layer for insert,update operation then is there any possibilities of problems? I mean multiple use access the method same time to insert data then what happen?




Responses

Posted by: Vuyiswamb on: 8/9/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Read about Static Methods here
http://msdn.microsoft.com/en-us/library/79b3xss3%28VS.80%29.aspx

I don't think there will be a problem , what were suspecting so that we can clear that Suspicion.


Thank you for posting at Dotnetfunda
[Administrator]

Ray.chayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Poster on: 8/9/2010 [Member] Starter

Up
0
Down
Generally all Data Access Layers are status (For example, all Data Application blocks provided by Microsoft is static). There will not be any problem if you keep your DAL as static. The only problem with static is its variables are shared across, so whatever variable you declare you declare in the method itself, do not use global variables (either class level or application level). However you can use connectionstring global variable as they are same for all the users).

The BAL and others layers should not be static as you will get problem in multi threading environment and will not be able to do performance testing properly.


As long as unique parameters are passed to static methods, it will not have any impact on multi threading environment.

Hope this helps.

Thanks

Ray.chayan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response