Wednesday, 12 September 2007

Stored procedures or inline SQL

The question is to be or not to be?

Right from the university days I have been tought that stored procedures are the best thing that can happen to a web developer. The reason why stored procedures are being advocated to students who are just into the field is unknown to be and I have never tried to explore them. Following are the reasons that are cited to them why to use stored procudures, but first let us know what is stored procedure.

Stored procedure are a very useful feature in SQL server. A stored procedure is a group of SQL statements that are compiled together and can be executed by calling a single command.

Uses for Stored Procedures:

1) Modular programming
2) Fast Execution
3) Network Traffic
4) Security

Sounds exciting when you read the book, but in practical, the picture is not as good as is depicted. I know of several projects, that are being developed with consideration of utilising the objects and/or modules from the project later on into another project. This is exactly why developers have implemented object oriented programming, and this is the reason, why .net has gained so much of popularity.

Moreover if the project is developed using n-tier architecture, then it would be more advisable to completely separate out the database from the rest of the modules. I have been wondering in the last project, about what is feasible, writing stored procedures or using the DAL(Data Access Layer) in the .NET architecure? Well technically both are same things, the former being stored on Data layer, which passes the data to the Business Logic Layer; and the later one being stored on Business Logic Layer, and accessing the data in the Data Layer!

Considering security, both are equally secure, because the system does not allow access to any processes outside the system to access the functions from the DAL. So what makes stored procedure, always a sought after option! I have been reading a couple of blogs recently regarding the same issue, and have found that the programming world has been divided into two segments on this issue! Those who recommend SPs and the ones that find them obsolete. Though there are many developers just like me, who are yet to make up their minds on whether to go for it, of its time to ditch them completely.

So far I have come across so many blogs that advocate both the approaches, that it is impossible for me to make a stand. But what I have learnt is both the camps are correct, in their ideologies. It all depends on the project and the approach a developer wants to implement!

For developers like me, who wish to implement the same module over and over again, without worrying for the database technology underneath; I recommend they should go for DAL. If you are worrying about the performance, leave it till the end and develop the whole project using DAL. You can tweak the bits and bobs here and there, later on to enhance the performance. If the purpose of the website is reporting, then you dont need security anyways, as you have the built in user profiling, and access control. If your website is not kind of reporting tool, then you dont have necessarily a performance issue, as the database connection is not going to be that frequent! so in either case, you dont justify the compulsion of using stored procedure.

I know there are issues related to using inline SQL commands, but then using stored procedure is not the only way to deal with it. If you would like to have a more detailed read, you can visit Frans Bouma's blog

Monday, 3 September 2007

Today was another learning experience. We in all are three developers usually working on the same files, repeatedly checking in and out of the source safe, but then at times, we all tend to save the files at the same time. this occurred when we accidentally commented out the email addresses, that a particular form need to be sent.

Now as things happen, we only realised it when we had an issue raised that people are not receiving confirmation email after submitting the forms. Lesson learnt!

Now we have devised two different methods, to bypass this bug. we are having all the email addresses in the web.config file, so no more accidental messing with the addresses in database or code file. we also are checking if the form is on live server, so as to prevent commenting out the send code, in order to prevent annoyed managers with inbox full of test emails.

The second method is to use the preprocessor directives, which will be disabled at the developer server. till today i haven't actually felt the need to use the preprocessor directives (Except from C++ classes in my uni; which was to score higher!). the only drawback for this system, is to remember when to turn off the declaration, and check it back in. this is the only reason we went for the first solution.

we have two different servers for live and development, and hence check the URL or IP address for the server. if the server isn't live, then don't send the mails. Also we have the preprocessor directives in place, so whenever we want to test the live server pages, just edit the directives, and prevent the emails being sent.

Simple solutions, but never thought of it that way!

BC30451: Name is not declared build error, for a label and radio button which are both declared.

This is a peculiar problem, which is not really a problem, but is a price that a developer has to pay for object oriented programming structure. because there may be another page in the system, that defines similar hierarchy of the elements, and uses the same names, the .Net framework, gets sort of confused which ones to load and what priority does it have.

for me it was a case, because i used to derive another page and name it as xyzTest.aspx instead of xyz.aspx thus having a work around for not messing up the working code, and can return to the original settings without worrying about which version to roll back to from the source safe. this technique works fine, but when i tried to publish the project, it gives out this error. apart from publishing, there is no error or warning that gets fired off, but strangely the publishing does not succeed! after reporting this to a couple of forums, and trial and error methods, i have found this to work.

still not sure if this was the reason for this error, so any one who has a alternate reason, can post a response.

CSS is case sensitive

Never thought Cascaded Style Sheets will be case sensitive. After a long time of coding in VB, and ASP, using Visual Studio 2005; I was kind of accustomed to coding in whatever case I wanted and wait for the VS2005 to take care of the case. Lately I have been having this problem in viewing the image button, incorrectly. the problem was further aggreivated, when there were two similar buttons with one showing the background image and the other one completely blank. After about an hour of excercise, with the stylesheet, I found out that I was writing one as Jobs_Feature and the other one as Jobs_feature. Bingo! Probably a lesson learnt hard way, but then i prefer to learn it this way rather than keep on reading books and trying to memorize
the facts and features of the stuff.

Further research shows that if the doctype declaration in the start of HTML page is not defined as XML, then CSS does not mind the different case in the class name, but the moment we declare the XML doctype, it turns out to be case sensitive. So this property of CSS can be attributed to XML. If you remember, XML has a standard, wherein the case of the tags and filename should always match.

Changing style of Drop down list.

I have been trying to change the border setting for multiple selection drop down menu in ASP.NET. After a bit of testing, I realised that all the style sheet code was not being rendered to the drop down list, when viewed in Internet Explorer. Mozilla FireFox was good enough, and even Safari, did help me out, but it was IE that did not budge! Then googling it gave me following explanation why IE did not work as expected.

"For historical reasons, some form-elements are elements from the operating system’s GUI. Rendering of these elements differs from browser to browser. Most of the browser, take into consideration the style sheet information about the element, and if not present renders the default properties from the OS’s GUI. For IE unfortunately these elements are <select>, <checkbox> and <radio>."