Dont trust the framework, to do the work
I just got some ugly outsourced code in my mail, that i was assigned to work on. Its clear the developer didnt know how the framework, works.. the code is from a webservice, that CRUDs some data from a sql-server. Aparently he was affraid of the SqlClient, so he made sure nothing bad happend
He used a variable, to state if a connection was open or not:
objCon = SqlCon();
intConState=1;
intConState=2;
objCon.Close();
intConState=3;
Whenever the connection was requested, he tried to open it:
private SqlConnection SqlCon()
{
SqlConnection objCon = new SqlConnection();
try
{
objCon.ConnectionString = m_strSQLCon;
objCon.Open();
}
catch(System.Exception objException)
{
throw objException;
}
return objCon;
}
When Calling a single stored procedure, he used a transaction
If a client requested some data, he didnt trust the build-in serialization and passed objects, so he did it himself.. Loaded the result from the sqlserver to a dataset, wrote the xml from the dataset (using WriteXml) to a memorystream. Loaded the xml into a XmlDocument, and finally returned it as a string using XmlDoc.OuterXml .. On the clientside he parsed the xmldocument manually.