Monthly Archives: May 2015

SQL Server CATCH block

Just like in Oracle SQL server allows the use of a catch block which can be very useful for debugging stored procedures!

First set up a transaction:

IF @@TRANCOUNT = 0
BEGIN TRANSACTION B4UPDATE
ELSE
SAVE TRANSACTION B4UPDATE

Then catch any errors and rollback if needed saving data about the issue.  If you also keep a variable with a step number you can also output this to an error table giving you the position where the code crunched!

BEGIN CATCH
ROLLBACK TRANSACTION B4UPDATE;
INSERT INTO ERRORS_SQL (TIMESTAMP, PROC_NAME, COMMENTS) VALUES (GETDATE(),‘BADGE_ALLOCATE_USEID’,‘errno: ‘ + ltrim(str(error_number())) + ‘ errmsg: ‘ + error_message())
COMMIT
END CATCH

SQL Server to_char conversion

When converting from oracle to SQL server you may struggle with Oracle to_char() and to_date() convertions.  SQL server handles this differently.  You have to used fixed types or you can use some clever madness.

For YYYYMMDDHH24MISS :

(SELECT REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(19), CONVERT(DATETIME, getdate(), 112), 126), ‘-‘, ”), ‘T’, ”), ‘:’, ”))

For DD/MM/YYYY HH24:MI:SS :

(select CONVERT(VARCHAR(10), GETDATE(), 103) + ‘ ‘ + convert(VARCHAR(8), GETDATE(), 14))

XAML relative size

How to size components to fit relative to parents in the tree:

Width=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}},Path=ActualWidth}”

Height=”{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}},Path=ActualHeight}”

Oracle Default Password Expiry

To prevent Oracle from expiring your accounts a few short months after installation you can turn off the auto expiring feature.  When there’s no need for super security the auto expiry is a major annoyance!

ALTER PROFILE “DEFAULT” LIMIT PASSWORD_LIFE_TIME UNLIMITED;
ALTER PROFILE “DEFAULT” LIMIT PASSWORD_VERIFY_FUNCTION NULL;
ALTER profile “DEFAULT” limit FAILED_LOGIN_ATTEMPTS UNLIMITED PASSWORD_LIFE_TIME UNLIMITED;
alter user <USERNAME> identified by <PASSWORD>;
alter user <USERNAME> account unlock;

signing java applets

Signing Java Applets:

No. Description Detail/Example
In the Dev Environment:
1. Create a folder and place all the jar files for the application inside. Mkdir s3idcertstore
2. Open CMD and move to the jar folder from step 1. Cd\s3idcertstore
3. Create a keystore “C:\Program Files (x86)\Java\jre1.8.0_25\bin\keytool” -genkey -keystore myKeystore -alias geoff -validity 9999
4. Add a basic MANIFEST.MF file in an META-INF folder to the jar file we want to sign. Manifest-Version: 1.0

Created-By: 1.7.0_71 (Oracle Corporation)

Application-Name: acms

Permissions: all-permissions

5. Sign the jar file “C:\Program Files (x86)\Java\jdk1.7.0_71\bin\jarsigner” -keystore myKeystore acms.jar geoff
6. Export the certificate so that it can be imported on a client PC. “C:\Program Files (x86)\Java\jdk1.7.0_71\bin\keytool” -exportcert -keystore myKeystore -alias geoff -file S3ID.cer
On the client PC:
1. Import certificate into trusted root certificate store. certmgr.msc
2. Update file permissions on client to allow java folder bin and lib folder update for allocator use. Also allow S3ID folder creation.
3. Run application without warnings or policy file update.