Tuesday, 22 February 2022

How to Get Full Context Menus in Windows 11

  1. Open Registry Editor 
  2. Navigate to HKEY_CURRENT_USER\SOFTWARE\CLASSES\CLSID\
  3. Create a new registry key called {86ca1aa0-34aa-4e8b-a509-50c905bae2a2} underneath CLSID
  4. Create a new key called InprocServer32 underneath {86ca1aa0-34aa-4e8b-a509-50c905bae2a2}
  5. Open the (Default) key in InprocServer32 and set its value to blank, then click OK.
  6. Close registry editor and reboot

Saturday, 19 February 2022

Can't Delete ARP Cache on Windows

arp -d produce an error: 

The ARP entry deletion failed: The parameter is incorrect.

Use the following command instead:

netsh interface ip delete arpcache


Wednesday, 24 November 2021

Windows 11 - Download and Install

  • Windows 11 Download Link
  • Install Windows 11 on non-TPM CPUs [reference]
    • Open registry editor
    • Registry Key: HKEY_LOCAL_MACHINE\SYSTEM\Setup\MoSetup
    • Name: AllowUpgradesWithUnsupportedTPMOrCPU
    • Type: REG_DWORD
    • Value: 1


Monday, 16 August 2021

Linux CentOS - Enable Network Adaptor and Assign Static IP Address

To deploy OVA or OVF file, 

  • Login to VCenter with the Administrator account
  • Make sure to use FQDN in URL instead of IP Address
  • In case image file cannot be recognized by the version of VCenter, run command shell as admin and issue the following command
    • tar -xvf yourfilename.ova

Follow the link below to assign a static IP address to the network adaptor. CentOS may or maybe use eth0 as network adaptor name and could be something like: ens32

Use #ip a to see the network interfaces. more...

Monday, 9 August 2021

NodeJS and SQL

// npm install express --save
// npm install mssql --save
// npm install -g nodemon
// nodemon app.js

var express = require('express');
var sql = require('mssql');
var app = express();

app.use(express.json()); // parse json body

var _PROTOCOL = 'HTTP';
var _SERVER = 'localhost';
var _PORT = 4444;
var _DEFAULTPORT = 9000;

// config for database
var config = {
    user: '****',
    password: '****',
    server: 'localhost',
    database: 'mosis_portal',
    stream: false,
    options: {
        trustedConnection: true,
        encrypt: true,
        enableArithAbort: true,
        trustServerCertificate: true, // incase recieve error: self signed certificate
    }
};

app.get('/posts', function(req, res) {
    sql.connect(config, function(err) {
        if (err) console.log(err);
        var request = new sql.Request();
        request.query('select * from posts').then(recordset => {
            console.log(recordset.recordsets);
            res.status(200).send(recordset.recordsets);
        });
    });
});

app.get('/post/:id', function (req, res) {
    var id = req.params.id;
    sql.connect(config, function(err, result, fields) {
        if (err) console.log(err);
        var request = new sql.Request();
        request.query(`select * from posts where id= ${id}`).then(recordset => {
            res.status(200).send(recordset.recordsets.pop().pop());
        });
    });
});

app.get('/title/:id', function (req, res) {
    var id = req.params.id;
    sql.connect(config, function(err, result, fields) {
        if (err) console.log(err);
        var request = new sql.Request();
        request.query(`select top 1 * from posts where id= ${id}`).then(recordset => {
            var info = recordset.recordsets.pop().pop();
            var title = info.post_title;
            var id = info.id;
            console.log(info.id)
            res.status(200).send(`<h1 onclick="location.href='http://localhost:4444/post/${id}'">${title}</h1>`);
        });
    });
});

app.listen(_PORT || _DEFAULTPORT, function() {
    console.log(`\n\nServer running: ${_PROTOCOL}://${_SERVER}:${_PORT || _DEFAULTPORT}`);
});


Tuesday, 4 May 2021

SQL Recursion

-- Recursive SQL
WITH t(n) AS (
  SELECT 1
  UNION ALL
  SELECT n+1 FROM t WHERE n< 5
)

SELECT n
FROM t


-- Data Generation with Recursive SQL
WITH
    t1(v1, v2) AS (SELECT 1, 2),
    t2(w1, w2) AS (
        SELECT v1 * 2, v2 * 2
        FROM t1
)

SELECT *
FROM t1, t2


Thursday, 4 March 2021

Detect SQL Database Changes using C# Table Dependency and SQL Broker

using System;
using TableDependency.SqlClient;
using TableDependency.SqlClient.Base;
using TableDependency.SqlClient.Base.Enums;
using TableDependency.SqlClient.Base.EventArgs;

namespace SQLCDC
{
                class Program
                {
                                static void Main(string[] args)
                                {
                                                string connectionString = "Server=localhost;Database=Test;Integrated Security=True;";
                                                var mapper = new ModelToTableMapper<People>();
                                                mapper.AddMapping(c => c.name, "Name");
                                                mapper.AddMapping(c => c.age, "Age");
                                                using (var dep = new SqlTableDependency<People>(connectionString, "People", mapper: mapper))
                                                {
                                                                dep.OnChanged += Changed;
                                                                dep.Start();
                                                               Console.ReadKey();
                                                                dep.Stop();
                                                }
                                }

                                public static void Changed(object sender, RecordChangedEventArgs<People> e)
                                {
                                                var changedEntity = e.Entity;
                                                if (e.ChangeType != ChangeType.None)
                                                {
                                                                switch (e.ChangeType)
                                                                {
                                                                                case ChangeType.Delete:
                                                                                                break;
                                                                                case ChangeType.Update:
                                                                                               break;
                                                                                case ChangeType.Insert:
                                                                                               break;
                                                                                case ChangeType.None:
                                                                                                Console.WriteLine("None");
                                                                                                break;
                                                                }
                                                }
                                                Console.WriteLine("DML OPR: " + e.ChangeType);
                                                Console.WriteLine("   Name: " + changedEntity.name);
                                                Console.WriteLine("    Age: " + changedEntity.age);
                                                Console.WriteLine();
                                }
                }
                public class People
                {
                                public string name { get; set; }
                                public string age { get; set; }
                }
}

/*
                use master
                select is_broker_enabled from sys.databases where name= 'Test'

                use test
                go

                create table people (
                                id int identity (1,1) not null,
                                name varchar(50) not null,
                                age nchar(10),
                                primary key (id)
                )

                select * from people
                insert into people (name, age) values ('A', 45)
                insert into people (name, age) values ('B', 50)
                insert into people (name, age) values ('C', 23)

                select * from people
                update people set name='A1' where name='A' 

                -- truncate table people

*/ 

Read more...

Analysis Service in Power BI Report Server

 We couldn’t connect to the Analysis Services server. Make sure you’ve entered the connection string correctly... link