Posts

Showing posts from March, 2014

Delete Db and Restore from a Backup.

Quick sql script to create a delete current test db and restore from a backup.  This one is just for tuesday and thursday. This is for a non-dev database, because it gets deleted and restored. if  exists(select * from sys.databases where name = 'ApplicationDBRestoreTest') BEGIN drop database ApplicationDBRestoreTest END DECLARE @myDatabaseName VARCHAR(100) = 'ApplicationDB_TTh.BAK' DECLARE @myDatabasePath VARCHAR(200) = N'\\sqldev\Backups\C-BCT-SQL01\' + @myDatabaseName RESTORE FILELISTONLY FROM DISK = @myDatabasePath RESTORE DATABASE ApplicationDBRestoreTest FROM DISK=@myDatabasePath WITH    MOVE 'ApplicationDB2005_Data' TO 'F:\SQL Server\TestRestore\ApplicationDBRestoreTest.mdf',    MOVE 'ApplicationDB2005_Log' TO 'F:\SQL Server\TestRestore\ApplicationDBRestoreTest_log.ldf' IF @@ERROR <> 0 EXEC ApplicationDB.dbo.spINSERT_ErrorLog_DbBackup @myDatabaseName ,'Restore Database Check','Failed', 'Restore

Convert Selected Code to User Control via Context Menu VS2012

Image
As you can see on the context menu, you have the option to use "Extract to User Control".  You can access this after highlighting some html and then right clicking.  Seeing that was completely unexpected, but in a good way.  After you select it, it  immediately moves the selected code to a User Control,  registers the created User Control with that page, then puts a placeholder for it in the same spot you previous code used to be.  Creating User Controls by hand it a bit annoying, so this is a great time saver.

AutoHotKey Going through Menus

Basically when you have to go through forms and dialogs you have to understand that there are times when you have to wait for the dialog to become available.  I modified a recursive function on the ahk forums to a while loop.  Personally I find recursion to be harder to follow then a simple loop even though they essentially do the same thing. Notice that I put an extra wait inbetween the "Disk Image" dialog and the "Add Disk Image" dialog.  It seemed that the code would sometimes try to execute on the top "Add Disk Image" dialog before it would actually close.  I spent some time trying to find a way after I made this work on the command line. Going through menus seems fraught with issues, so I really wanted to change this. I feel kind of irritated that in order to get it working in the command line I only had to do append a space and put the file name.  Neko Project is the same way, only I do not know how to get it to go fullscreen from outside the co

Importance of Understanding SQL Transactions

Yesterday we encountered a disaster where a lot of records were gone.  After digging for a while the root cause was something like this:  BEGIN TRAN -- DELETE --records in table -- INSERT INTO Livetable    --values --SELECT    from table -- COMMIT TRAN Basically the insert into from a select failed, but the delete passed.  Whoever wrote that code did not understand that by default transactions will only rollback the statement that generated the error unless it is above a certain error level. A useful post is from here: http://sqlinthewild.co.za/index.php/2011/05/17/on-transactions-errors-and-rollbacks/ The author shows example sql:  CREATE TABLE TestingTransactionRollbacks (  ID INT NOT NULL PRIMARY KEY ,  SomeDate DATETIME DEFAULT GETDATE()  ) ; GO BEGIN TRANSACTION -- succeeds INSERT INTO TestingTransactionRollbacks (ID)  VALUES (1) -- Fails. Cannot insert null into a non-null column INSERT INTO TestingTransactionRollbacks (ID)  VALUES (NULL) -- succeed

Baby Jesus Cries Every Day This Code Is Here

Found something amusing here. Having read about crap like this on dailywtf but to actually encounter it myself is...interesting. < script type =" text/javascript "> var _kmq = _kmq || []; var _kmk = _kmk || '543704820507c2a323f44ddcbcd60ad6d5a8ae95'; function _kms(u){ setTimeout(function(){ var d = document, f = d.getElementsByTagName('script')[0], s = d.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = u; f.parentNode.insertBefore(s, f); }, 1); } _kms('//i.kissmetrics.com/i.js'); _kms('//doug1izaerwt3.cloudfront.net/' + _kmk + '.1.js'); //TODO: TEMPORAL CODE. UGLY HACK. BREAKS EVERY KNOWN PRINCIPLE OF A GOOD ARCHITECTURE OR DESIGN //TODO: I MEAN IT, BABY JESUS CRIES EVERY DAY THIS CODE IS HERE. // Instead of getting and waiting for a cosmetrics user id, replicate the cos

First Exposure to AutoHotKey

So I have found an interesting toy to mess with. AutoHotKey . AutoHotKey is a scripting platform to perform and automate actions within Windows. At work we use Automate 9 to perform sending and downloading files via s/ftp, and notification actions based on data within our databases. The two seem to be quite similar, but it seems like AutoHotKey is a lot lower level. With Automate 9 you have a gui with a toolbox on the side with various actions that allow drag and drop capability. As a programmer I find AutoHotKey a lot more familiar since the syntax is relatively similar to modern programming languages. Automate 9 on the hand took me awhile to figure what was going on, and that program has a lot of quirky, unusual, and unhelpful behavior. Well, I am familiar with C-type languages and Vb.Net, and messed with Lua while back, and I can grasp proper AHK syntax without too much trouble. Although I have to confess that some of the syntax regarding variables is a little unexpected.