Killing other processes connected to an MSSQL database

declare @db_name varchar(100) = 'dbname';
declare @kill_commands varchar(max) = '';

@kill_commands=@kill_commands+'kill '+convert(varchar(5),spid)+';'
from master..sysprocesses
spid <> @@SPID -- avoid to kill the current process
and dbid=db_id(@db_name)

print 'Executing: ' + @kill_commands;
exec (@kill_commands);

Lists all foreign keys (source and ref columns) in a MSSQL database

This script lists all foreign key references in a MSSQL database, using system tables:

SELECT AS TableWithForeignKey, AS ForeignKeyColumn, AS ReferencedTable, AS ReferencedColumnName
FROM sys.foreign_key_columns AS fk
inner join sys.tables AS t
on fk.parent_object_id = t.object_id
inner join sys.columns AS c
on (t.object_id = c.object_id
AND fk.parent_column_id = c.column_id)
inner join sys.tables AS r
on fk.referenced_object_id = r.object_id
inner join sys.columns AS rc
on (r.object_id = rc.object_id
AND rc.column_id = fk.referenced_column_id)


Django email setup on Hostgator

On Hostgator it is possible to run Django applications with FastCgi, but it has only sendmail as email back-end which is not included in Django.

Hopefully there is a snipets to resolve this limitation. You just needed to change the path of the sendmail file and it was ready to run. The location of sendmail is "/usr/sbin/sendmail" on our Hostgator server.

And the email backend should be configured in your by adding the following line:

EMAIL_BACKEND = 'sendmail.EmailBackend'

Dajngo app unicode JSON repsonse

If your django application has unicode data, and your view uses jquery and JSON response, do not forget to specify the encoding for the mimetype:

return HttpResponse(simplejson.dumps(your_data),
mimetype='application/json; charset=utf-8')

Open OpenOffice documents from a network share using nautilus

Under my gnome desktop, I had a problem when tired to open documents from a network share with OpenOffice. When I tired the spalsh screen appeared, but the document did not open.

After some searching I found the debian squeze has a package I was curious what is the difference between the standard package and this one. Soon I found it's home page:

Almost the first line said:

Gnome-VFS - G/OO.o allows transparent access to allow documents to be loaded / saved from a range of Gnome VFS backends, eg. Samba shares.

I installed and the problem went away.