Thursday, October 30, 2014

Eclipse - Configuration - how to change project type

Background:
I have imported a java project (not sure the project was created as Java Project) in Eclipse but it wasn't giving any IntelliSense (code suggestion), errors were not marked, build automatically etc. "(Project) - Properties" (alt + enter) was not providing all the option usually seen in regular java project. That led me to think that eclipse is not able to recognize this project as valid java project.

Solution:
Change the project type solved the issue. Actually I had to deselect 'Java' - Save and than open again and select 'Java' to make it work.

How to change project type in eclipse
1. "(Project) - Properties" (alt + enter)
2. From left navigation panel, select 'Project Facets'
3. From right side, select 'Java' and appropriate version from drop down. 
4. Apply and Save

When selecting 'Java' in project facet first time:
When 'Java' is selected as first time facet for a project, a new link 'Further configuration available...' will appear at the bottom. That will allow to specify source and build path. Always good idea to check that link

Few shortcuts:
1. "Alt + Enter" - will open the Project Properties 



Tuesday, October 14, 2014

SQL Server - Coding - Update data in tables related by foreign constraint

Environment: SQL Server 2008

Background: I need to update id column value of a table which has corresponding data in a child table and integrity enforced by foreign key constraint. Relationship between tables and data excerpt present below. Need to change 'ROLE_EXEMPTION' with value 'ROLE_AMLM_QA1_EXEMPTION'.

Table relationship:
















Data in tables:















Script to fulfill the need:

DECLARE @changedValue VARCHAR(100) = 'ROLE_AMLM_QA1_EXCEMPTION',
@originalValue VARCHAR(100) = 'ROLE_EXEMPTION'
;

-- Disable all table constraints
ALTER TABLE wk_sec_role_resource_mapping NOCHECK CONSTRAINT ALL;

-- Update parent table record
UPDATE wk_sec_roles SET role_id=@changedValue WHERE role_id=@originalValue;
-- Update child table record
UPDATE wk_sec_role_resource_mapping SET role_FK=@changedValue WHERE role_FK=@originalValue;

-- Enable all table constraints

ALTER TABLE wk_sec_role_resource_mapping CHECK CONSTRAINT ALL;


Necessary info:

-- Disable all table constraints
ALTER TABLE MyTable NOCHECK CONSTRAINT ALL

-- Enable all table constraints
ALTER TABLE MyTable CHECK CONSTRAINT ALL

-- Disable single constraint
ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint

-- Enable single constraint
ALTER TABLE MyTable CHECK CONSTRAINT MyConstraint
-- disable all constraints

EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

Wednesday, June 25, 2014

Virtual Box - Error - starting VM shows "Couldn't read from the boot medium! System halted."

Environment
1. VirtualBox 4.3.12 (Windows)
2. Host operating system - Windows 2008 R2
3. Guest operating system - Windows 2012

Error description:
Copied the VM from another machine and tried to run the VM. In VM window, it shows error message "Couldn't read from the boot medium! System halted".


Solution-01Hard drive is not associated

Steps to follow - 
1. Select VM and go to settings
2. In the settings wizard, click storage from left navigation
3. At right side, under 'Controller: SATA", click "Add Hard Disk"
4. Point  to the hard drive which need to be associated to the VM



Virtual Box - Error - Cannot Access the kernel driver

Environment: Virtual Box 4.3.12 (windows)

Error description:
"Cannot Access the kernel driver! Make sure the kernel module has been loaded successfully."

Solution-01:
1. \Oracle\VirtualBox\drivers\USB\filter\VBoxUSBMon.inf - right mouse > install
2. \Oracle\VirtualBox\drivers\vboxdrv\VBoxDrv.inf - right mouse > install

Solution-02: this worked for me
1. Unistall VirtualBox
2. Restart machine
3. Install again VirtualBox



Wednesday, June 4, 2014

SQL Server - Setup - enable/disable SNAPSHOT isolation level

Environment:
1. SQL Server 2008

Background:
I need a script which would change isolation level to SNAPSHOT on current database. I tried to use CURRENT to make it work without much success. Instead used DB_NAME() built-in function to get the current database name and executed alter command as run time query.

Script snippet:

DECLARE @dbName VARCHAR(100) = '';
SELECT @dbName=DB_NAME();
IF ISNULL(@dbName, '') <> ''
BEGIN
DECLARE @cmd NVARCHAR(100) = 'ALTER DATABASE '+@dbName+'  SET ALLOW_SNAPSHOT_ISOLATION ON';
EXECUTE sp_executesql @cmd;
END;
GO


Helpful commands:


To enable:
ALTER DATABASE ABC SET ALLOW_SNAPSHOT_ISOLATION ON;

To disable:
ALTER DATABASE ABC SET ALLOW_SNAPSHOT_ISOLATION OFF;


How to check database isolation settings:
SELECT name
        , s.snapshot_isolation_state
        , snapshot_isolation_state_desc
        , is_read_committed_snapshot_on
        , recovery_model
        , recovery_model_desc
        , collation_name

FROM sys.databases s

Friday, May 16, 2014

SQL Server - Coding - Find out tables those are related

Environment: Tried on SQL Server 2008

First Query: Show all tables from the database where parent-child relationship is present 

SELECT
OBJECT_NAME(rkeyid) parent_table,
OBJECT_NAME(fkeyid) child_table,
OBJECT_NAME(constid) fkey_name,
c1.name fkey_col,
c2.name ref_keycol
FROM SYS.SYSFOREIGNKEYS s
INNER JOIN SYS.SYSCOLUMNS c1
ON ( s.fkeyid = c1.id and s.fkey = c1.colid )
INNER JOIN SYSCOLUMNS c2
ON ( s.rkeyid = c2.id and s.rkey = c2.colid )

ORDER BY parent_table,child_table
;


Second Query: Show all parent tables of a particular table

SELECT
OBJECT_NAME(rkeyid) parent_table,
OBJECT_NAME(fkeyid) child_table,
OBJECT_NAME(constid) fkey_name,
c1.name fkey_col,
c2.name ref_keycol
FROM SYS.SYSFOREIGNKEYS s
INNER JOIN SYS.SYSCOLUMNS c1
ON ( s.fkeyid = c1.id and s.fkey = c1.colid )
INNER JOIN SYSCOLUMNS c2
ON ( s.rkeyid = c2.id and s.rkey = c2.colid )
WHERE OBJECT_NAME(fkeyid) = '
'


ORDER BY parent_table,child_table


Third Query: Show all child tables of a particular table

SELECT
OBJECT_NAME(rkeyid) parent_table,
OBJECT_NAME(fkeyid) child_table,
OBJECT_NAME(constid) fkey_name,
c1.name fkey_col,
c2.name ref_keycol
FROM SYS.SYSFOREIGNKEYS s
INNER JOIN SYS.SYSCOLUMNS c1
ON ( s.fkeyid = c1.id and s.fkey = c1.colid )
INNER JOIN SYSCOLUMNS c2
ON ( s.rkeyid = c2.id and s.rkey = c2.colid )
WHERE OBJECT_NAME(rkeyid) = '
'

ORDER BY parent_table,child_table


Reference:
1. Concept is taken from an online article, unfortunately don't have link

Wednesday, February 26, 2014

Power Shell - Error - File cannot be loaded. PSSecurityException.

Exception
File D:\Downloads\AMLM_Module_Builds \AML_Module_1.4.2_hotfix_1.4.2.13\DeployAMLM.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:17
+ .\DeployAMLM.ps1 <<<<
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException


Solution-01:
To run unsigned scripts that you write on your local computer and signed scripts from other users, use the following command to change the execution policy on the computer to RemoteSigned:
            set-executionpolicy remotesigned


Tuesday, February 25, 2014

Design - Java + SQL Server - Discussion about file based vs database storage for file upload

Background:
Below investigation done considering java application with SQL Server as back-end. Java - 1.6 and SQL Server - 2008 r2. 


1. Comparison table (Source-01, Source-04)

Comparison point
Storage solution
File server / file system
SQL Server (using varbinary(max))
FILESTREAM
Maximum BLOB size
NTFS volume size
2 GB – 1 bytes
NTFS volume size
File Size recommendation
>1MB
<256kb o:p="">

>1MB
Note: File size between >256KB and <1mb b="" is="" need="" project="" subject="" to="">Source-01
)
Streaming performance of large BLOBs
Excellent
Poor
Excellent
Security
Manual ACLs
Integrated
Integrated + automatic ACLs
Cost per GB
Low
High
Low
Manageability
Difficult
Integrated
Integrated
Integration with structured data
Difficult
Data-level consistency
Data-level consistency
Application development and deployment
More complex
More simple
More simple
Recovery from data fragmentation
Excellent
Poor
Excellent
Performance of frequent small updates
Excellent
Moderate
Poor
Data Encryption
(
Source-04)
Manual
Possible
Manual
DR
Manual Data Replication
SQL Server Data Replication (log shipping, Data  Mirroring, Always ON)
SQL Server Data Replication (log shipping, Always ON)
Backup and Restore
Manual (3rd party tools or OS command can be used)
Part of database backup and restore
Part of database backup and restore
Single point failure/ High availability
Redundant File Servers plus SAN implementation provides no single point failure
SQL Server Clustering plus SAN provides no single point failure
SQL Server Clustering plus SAN provides no single point failure. FileStream should also be on SAN.
TDE (Transparent Data Encryption)
NA
Possible
Not Supported
Database Mirroring
NA
Possible
Not Supported
SNAPSHOT Isolation
NA
Possible
Partially Supported (explanation below)
Authentication
Only Windows Authentication
Supports both SQL Server Authentication and Windows Authentication
Does not support SQL Server Authentication. Only Windows Authentication


2. If we use VARBINARY without filestream enabled, research done by Microsoft indicates – file size <256kb better.="" database="" file="" is="" size="" storage="">1MB file system is better (can be regular file system (NTFS) or FILESTREAM (SQL SERVER). (Source-02)

3. FILESTREAM uses the NT system cache for caching file data. This helps reduce any effect that FILESTREAM data might have on Database Engine performance. The SQL Server buffer pool is not used; therefore, this memory is available for query processing.
(Source-03)

4. FILESTREAM integrates the SQL Server Database Engine with an NTFS file system by storing varbinary(max) binary large object (BLOB) data as files on the file system. Transact-SQL statements can insert, update, query, search, and back up FILESTREAM data. Win32 file system interfaces provide streaming access to the data. (Source-03)

5. Limitation of FileStream of MS SQL Server
  1. TDE (Transparent Data Encryption) is not possible
  2. Database mirroring is not supported for FileStream
  3. SNAPSHOT isolation is not fully supported. If a FILESTREAM filegroup is included in a CREATE DATABASE ON clause, the statement will fail and an error will be raised.
  4. When you are using FILESTREAM, you can create database snapshots of standard (non-FILESTREAM) filegroups. The FILESTREAM filegroups are marked as offline for those database snapshots
  5. For failover clustering, FILESTREAM filegroups must be put on a shared disk. FILESTREAM must be enabled on each node in the cluster that will host the FILESTREAM instance
  6. It’s highly recommended to have separate file group in database to handle FileStream
  7. FileStream supports Windows authentication only 


Sources:
  1. http://msdn.microsoft.com/library/hh461480
  2. http://research.microsoft.com/apps/pubs/default.aspx?id=64525
  3. http://msdn.microsoft.com/en-us/library/gg471497.aspx
  4. http://msdn.microsoft.com/en-us/magazine/dd695918.aspx
  5. http://technet.microsoft.com/en-us/library/bb895334.aspx



Sunday, February 2, 2014

Java - Setup - Install Oracle JDK in Ubuntu

JDK Version: Java 7 (and 1.6.0_45 64bit)
Operation System: Ubuntu 14.04 (and Ubuntu 12.04 64 bit)



Check if java is installed:
Command: java -version

If below message is displayed on screen, meaning java not installed

The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.8-jre-headless
 * openjdk-7-jre-headless
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless

Try: apt-get install



How to remove openJDK
This step might be needed if openJDK is not preferred and want to install Oracle JDK.

Command: "sudo apt-get purge openjdk-\*"

Install JDK - steps to follow :
  • Install packages directly. Below commands are for Java 7. Might need to change with 'Java7' to appropriate version (like Java8).
    Commands:
    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java7-installer
    sudo apt-get install oracle-java7-set-default
  • Using .bin extension installer (this I tried with Java 6 on Ubuntu 12 earlier)
    1. Download JDK version from Oracle. File name is 'jdk-6u45-linux-x64.bin'
    2. Copy downloaded folder to '/usr/local/java'. (need to create the folder if desn't exist)Command: "sudo mkdir -p /usr/local/java" (to create folder)"sudo cp jdk-6u45-linux-x64.bin /usr/local/java/"
    3. Set the executable permissionsCommand: "sudo chmod a+x jdk-6u45-linux-x64.bin"
    4. Add java to the path.
      C
      ommand:"sudo gedit /etc/profile" (gedit editor is used)
      Lines need to be added in the profile. 
      JAVA_HOME=/usr/local/java/jdk1.6.0_45PATH=$PATH:$HOME/bin:$JAVA_HOME/binJRE_HOME=/usr/local/java/jdk1.6.0_45/jrePATH=$PATH:$HOME/bin:$JRE_HOME/binexport JAVA_HOMEexport JRE_HOMEexport PATH
    5. Inform Ubuntu where to look for JDKCommand:"sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.6.0_45/jre/bin/java" 1"
      "sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.6.0_45/bin/javac" 1
      "
      "sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.6.0_45/bin/javaws" 1
      "
    6. Inform Ubuntu Linux system that Oracle Java JDK must be the default JavaCommand: "sudo update-alternatives --set java /usr/local/java/jdk1.6.0_45/jre/bin/java"
      "
      sudo update-alternatives --set javac /usr/local/java/jdk1.6.0_45/bin/javac"
      "
      sudo update-alternatives --set javaws /usr/local/java/jdk1.6.0_45/bin/javaws"
    7. Load profile changesCommand:  "./etc/profile"

Test java successfully installed:

Command: "java -version"

Output: 
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)