Tuesday, June 30, 2009

Http Module not loading in IIS

For the project i am working on we created an Authorization component which loads as Http Module and works on the user credentials.
The module was defined in web.config for the web application and was working fine. Until one day i tried to play with App pool settings of IIS and then the module just stopped loading.
After doing some searches on web i finally figured out the problem. While playing with the App pool settings i had changed it to run in Integrated mode from the Classic mode.
When i run my application pool in the Integrated mode the module has to be specified in web.config as an entry under system.webserver tag while if i am using the classic mode the http module has to be specified under system.web tag of web.config.

How this matters and what these 2 modes mean is something i still have to figure out but for now i am happy that my module is up and running for me to go ahead and work on my tasks :)

Happy coding


Thursday, June 18, 2009

HTTP Error 503. The service is unavailable.

Another one of those errors which drives a developer crazy.
One of the reasons it could be occurring is because your site is running under an AppPool which is unable to start because of reasons like wrong identity etc.
The problem is that it is very difficult to catch this since the site seems to be up and running in IIS 7 management console.
Once you reach the place where all the App Pools would be listed you might see that the App Pool is not yet started and hence the problem. There's no way that the Management Console would give you a hint as to what might be going on. At least on the Console it looks like everything is up and running fine.
So next time you see a Http Error 503 you can go and check the App Pool settings before doing anything else.
@IIS Console team :-It should be easy to figure this one out and display an error to administrator saying something is wrong with App Pool settings.

Happy coding...


Tuesday, June 9, 2009

Name of the server on which a query is executing

Sometimes while executing a batch of queries it is a must to find out what server the batch is executing on. e.g. while creating a linked server you might not want to create a linked server for the local server.
This can be achieved by querying the sys.servers table and check for the server with server_id 0.
so the query to do this is

select name from sys.servers where server_id = 0

Happy coding...


Monday, June 8, 2009

Synonyms and Linked Servers in SQL Server

Someone in my project wrote a perl script which used to generated a SQL script to create synonyms to other databases.
Now this SQL Script to create synonym used to run after the required databases were deployed and it uses to work fine till we went into the pre production deployment phase of the project. And as soon as we reached to this environment the setup itself started failing. The only difference between this environment and the test environment was that the databases were hosted in different machines.
After some investigation we established that the generated SQL script didn't take this into consideration. It was working fine in dev environment since all the databases were hosted in a single machine. As soon as the databases were separated the names of databases we were referring to in the script became invalid.

Linked servers came to rescue in this situation. Basically we added a Linked server to the server we wanted to create synonyms in and qualifies the table names with the linked server names as well.

On digging further the Linked server is an important and useful feature in SQL Server since it can not only make one SQL server interact with another, it can actually make SQL Server interact with any other OLE Source.
We can even use it to do the distributed transactions across various data sources.

Quickest way to Add a linked server to the database is to use the wizard in SQL Server Management Studio. One can also use stored procedure sp_addlinkedserver in the master database. sp_serveroption can be used to configure the options on how to connect to this linked server.

More information can be found here.

Friday, June 5, 2009

Enabling SQL Server to access directories...

I am working on SQL Server nowadays and while writing a component to restore a database programatically from a backup file one needs to access the file system from within the database.

Now normally a database won't allow you to do so as ideally a database shouldn't depend on anything outside it. Even the metadata of database's own schema is stored within the database (One of the basic principles of database).
In order to enable database to access the file system we can use the following script...

exec sp_configure 'show advanced options', 1
exec sp_configure 'xp_cmdshell', 1
exec sp_configure 'show advanced options',0

Happy coding,