Tuesday, December 15, 2009

Drop table with Foreign Key constraints

I spent a while trying to find on google how to Drop a table in SQL Server that has been referenced by other tables in the database in vain. So finally I ended up doing the following:

1) Open Query Editor in SSMS (SQL Server Management Studio)

2) Run this with "Results to Text" (Right click Results => Results to Text)

3) Copy/Paste the output in a SQL window and execute


SELECT 'ALTER TABLE ' + OBJECT_name(sysfk.fkeyid) +

' DROP CONSTRAINT ' + OBJECT_name(sysfk.constid) + CHAR(13) + CHAR(10) +

'GO'

FROM sysforeignkeys sysfk,

syscolumns parent_table,

syscolumns child_table

WHERE sysfk.fkeyid = child_table.ID

AND sysfk.fkey = child_table.COLID

AND sysfk.rkeyid = parent_table.ID

AND sysfk.rkey = parent_table.COLID

AND OBJECT_name(sysfk.rkeyid) = 'TABLE_NAME'


Wednesday, December 9, 2009

Active Record with SQL Server

To drive Silverlight applications using Watir, and actually modifying/editing the database with ActiveRecord a number of gems need to be installed.

  • gem install watir
  • gem install rspec
  • gem install rake
  • gem install activerecord
  • gem install rubyzip
  • gem install activerecord-sqlserver-adapter --source=http://gems.rubyonrails.org

Also copy the ADO.rb file [1] and place it in the following dir:

X:/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb

We need to install the rubyzip gem so that the unzip/zip functionality could work.

Minor changes to the 'sa' user had to be made. For that goto the SQL Server Management Studio Express. Under Security -> Logins; right click and goto the properties of the 'sa' user.

Under status change Login to 'Enabled'. Save changes.

Goto Start -> Programs -> Microsoft SQL Server 2005 -> Configuration Tools -> SQL Server Configuration manager. Restart the SQL Server Express.

PS If you cannot login using the 'sa' credentials: Right click on the server (after logging in using Windows Authentication) Go to security -> change permission to mixed mode.

Wednesday, May 27, 2009

Unhandled Error in Silverlight 2 Application Code: 4004 Category: ManagedRuntimeError

I spent so much time trying to figure out what was wrong with the Virtual Directory. Well it seems that in IIS 7 I was missing the handler for *.svc files.

Added to a Handler Mapping for
Request Path *.svc
Executable: %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
Name: SVc-ISAPI-2.0

Guess what? It works like a charm.