# Monday, October 26, 2009

Deleting Registry values with a .reg file

Sometimes you just want to do something simple in a batch file, and I'd always thought it wasn't possible to 'delete' a value in a .reg file (as the file is applied as a 'merge'), but it is...

Just replace the value with a - (minus)...

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoDriveTypeAutoRun"=-



posted on Monday, October 26, 2009 10:16:01 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [1]
# Friday, October 09, 2009

Software Developer vs Project Manager

I came across a hilarious (full of swearing) video the other day created through Xtranormal.com.  This amazing site gives you all the tools to just plug in a script and direct your own movie, along with amusing generated voices.

Here's my first effort to illustrate the sometimes rocky relationship between developers and project managers...

Watch on Xtranormal.com | Watch on Youtube
posted on Friday, October 09, 2009 10:33:55 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]
# Thursday, October 01, 2009

SQL Server - Insert to table with ALL default values

If you're trying to do an insert to a table where every column has a default value (or is an identity column), then SQL Server will give you an error if you don't specify 'something' in the field list/values clause... Or so I thought...

This is so simple it's funny, but not so simple to find in the documentation:

INSERT INTO TableName DEFAULT VALUES



posted on Thursday, October 01, 2009 9:01:02 AM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]
# Monday, September 28, 2009

SQL Server Stored Procedure to disable / enable all foreign keys and constraints in a database

I've been doing a bit of batch archiving work, and needed a nice and quick way to disable foreign keys and other constraints without actually removing them.  I found a nice article on disabling all constraints in a database, and thought I'd just take it one step further by making it into a Stored Procedure, and adding a parameter to toggle whether the constraints are enabled or disabled.

Nice and easy.  Here's the script.


USE [YOURDBNAME]
GO

IF  EXISTS 
(SELECT FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SetDBTableConstraints]'AND type in (N'P'N'PC'))
DROP PROCEDURE dbo.usp_SetDBTableConstraints
GO

CREATE PROCEDURE 
dbo.usp_SetDBTableConstraints(@Enable BIT)

AS

/*** DISABLE/ENABLE ALL TABLE CONSTRAINTS ************************

This script will disable all constraints on all tables within the database
that it is run in.

************************************************************/

SET NOCOUNT ON
SET ROWCOUNT 


DECLARE @Count INT
DECLARE 
@String NVARCHAR (1000)
DECLARE @ConstraintName VARCHAR(128)
DECLARE @TableName VARCHAR(128)

--Find all constraints and their respective tables from the sysobjects table and place into a temp table.
--Primary Key and Unique Constraints via Unique Indexes are not disabled through this command
--You should use the ALTER INDEX...DISABLE command in SQL Server 2005
SELECT 
        name                     AS 
constraintname,
        object_name(parent_obj)  
AS tablename 
INTO #Const_Table
FROM sysobjects s 
where xtype in ('F')

SELECT @Count Count(*) FROM #Const_Table

--Setting the rowcount to one allows for one row from the temp table to be picked off at a time.
--Used as an alternative to a cursor.
SET ROWCOUNT 1

--Loop until all rows in temp table have been processed.
WHILE @Count > 0
BEGIN
    
--The rowcount of one ensures that only one tablename and constraint name is picked.
    
SELECT @TableName TableName, @ConstraintName ConstraintName
    
FROM #Const_Table

    
--Build execution string to disable constraint.
    
IF @Enable 
        
SET @String 'ALTER TABLE ['+ @tablename + '] CHECK CONSTRAINT [' + @constraintname +']'
    
ELSE
        SET 
@String 'ALTER TABLE ['+ @tablename + '] NOCHECK CONSTRAINT [' + @constraintname +']'

    
--Execute the SQL
    
EXEC sp_executesql @string

    
--Remove this row from the temp table, since it has now been processed.
    
DELETE FROM #Const_Table WHERE ConstraintName @ConstraintName and TableName @TableName

    
SET @Count @Count - 1
END -- Loop

SET ROWCOUNT 0

DROP TABLE #Const_Table
 

GO
posted on Monday, September 28, 2009 12:34:45 PM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]
# Friday, August 14, 2009

Coder T-Shirts from Geek Casuals

OK - I do T-Shirts, and I'm just plugging my more geeky brand 'Geek Casuals', but some of these may appeal to the .NET audience....





Geek Casuals - Geekwear that geeks wear..


posted on Friday, August 14, 2009 8:43:12 AM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [1]
# Monday, July 20, 2009

Remote Desktop Clipboard Not Working? - Just restart rdpclip

This one's been bugging me for years.  You know the situation, you're happily using a remote desktop connection, and all of a sudden the clipboard stops working for no apparent reason.

I recently stumbled across a 'fix' for this.  It's more of a workaround than a fix, as you'll need to do it every time the clipboard disappears.

Just look for a process named rdpclip.exe on the machine you're remoting to, and kill it, then restart it.

You should find you're able to copy/paste again. 

posted on Monday, July 20, 2009 12:01:17 PM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]
# Tuesday, June 16, 2009

Questions every team and dev lead should ask themselves

Pearls of wisdom from Roy Osherove.  I've had a similar list in the past so this is a great reminder to 'keep improving'.


posted on Tuesday, June 16, 2009 7:39:30 PM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]
# Monday, June 15, 2009

Using JQuery with DotNetNuke 4.x

I'm currently doing a project using DotNetNuke, and we're using JQuery plugins to achieve certain content rotation and scroller functionality.  All was 'amost' good as I'd found a way to inject the JQuery script to the page header on a per-skin basis, but in 'edit' mode the actions button wasn't showing up at the top of containers in FireFox and was causing JavaScript errors in IE.

I'd already gone through the hoops of declaring jQuery.noConflict(), but it still appeared to be conflicting with the dnn:actions (solpartactions) control.  I'd read somewhere else about Solpart code being incompatible with JQuery.

I tried one last thing, adding the noConflict() call in the JQuery library script file itself - rather than running as a fragment on page load.  This fixed everything, as something else was obviously getting in and hijacking in the meantime.  Apparently with V5 this will all be fixed as JQuery's more integrated with the framework.  Anyway, for those interested here's what I had to do to get JQuery (and associated plugins) talking nicely whilst still allowing the actions menu to pop up on my containers...

  1. Amend the JQuery library (jquery.1.x.x.min.js) by adding the following line at the bottom...

    jQuery.noConflict();

  2. Amend the skin you want to load the jquery library (and plugins) in (we've got it only in specific skins to avoid the overhead where it's not required).  You could also do this in the module by checking 'if loaded', but here's the code for a skin (in ascx file)...

    <script runat="server">
        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'add a script reference for Javascript to the head section
            AddScript("/js/jquery.scrollable-1.0.2.min.js")
            AddScript("/js/jquery.mousewheel.js")
            AddScript("/js/jquery-1.3.2.min.js")
        End Sub
       
        Private Sub AddScript(ByVal fileName As String)
            Dim oLink As New HtmlGenericControl("script")
            oLink.Attributes("language") = "javascript"
            oLink.Attributes("type") = "text/javascript"
            oLink.Attributes("src") = fileName
            Dim oCSS As Control = Me.Page.FindControl("CSS")
            If Not oCSS Is Nothing Then
                oCSS.Controls.AddAt(0, oLink)
            End If
        End Sub
    </script>


    The order is important, as we're adding the scripts to the 'top' of the scripts each time.  JQuery needs to be the first referenced.
  3. Make sure that anywhere you use jQuery you use the jQuery(xx) syntax, and not $(xx).
That's it.

posted on Monday, June 15, 2009 3:41:01 PM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]