I would like to know if there are any pitfalls on calling a static method from an ASP.NET web service.
internal static object SelectScalar(String commandText, DataBaseEnum dataBase)
{
SqlConnection sqlc = new SqlConnection(AuthDbConnection.GetDatabaseConnectionString());
object returnval=null;
if (sqlc!=null)
{
SqlCommand sqlcmd = sqlc.CreateCommand();
sqlcmd.CommandText = commandText;
sqlc.Open();
returnval = sqlcmd.ExecuteScalar();
}
return returnval;
}
So for an example the method above; are there any pitfalls on multiple web methods and multiple clients calling this method at the same time (say, 1000 calls to a web method that calls this function)?
Since you’re creating a new
SqlConnection, you want to dispose it or the connection won’t close. See MSDN for usage guidelines.The fact that its a static method though… that doesn’t seem to be an issue since you’re not updating any shared state (global variables).
EDIT: AFAIK, the ‘pitfalls’ of static methods in webservices are the same as in any other application. The only thing to keep a note of is that a webservice is a server that is expected to run reliably for a long period of time. Thus things that could cause problems over time (memory leaks, db connection exhaustion, etc) are more significant than for other applications that run for a much shorter time period.