Saturday, March 16, 2019

Just some update

wanna write in mandarin but then the typing is not suitable for me. so continue in english
Time really passes, yesterday night in penang, I met my good friend  in secondary school.
we didn't meet for 18 years since after form 5. I think we still met at form 6 awhile after that no more.
As he said, when think back it was like yesterday we just graduated form 5. then suddenly we are married with kids. 
i also told him that in my 20 to 30, I spent too much of time playing games. now i need to put in double effort to chase back the time i lost.

Monday, March 11, 2019

Query MS Excel File using MS SQL Script


SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.16.0',
'Excel 12.0; Database=e:\excelimport\leadmaster.xlsx; HDR=YES; IMEX=1',
'SELECT * FROM [LeadMaster$]');

if you try to run above  SQL script , it show some errors, (after modifying the path and also sheet name).
Such as access denied or cannot find the server. you should try below steps


Go into your MSSQL management server studio,
go to connected-> Service objects-> Linked Servces->Provideres
you should see Microsoft.ACE.OLEDB.xxxx (12.0,15.0 or 16.0) depend which database engine you have installed.
Usually this will not be seen on MS Windows Server if you don't have MS Excel installed.
https://www.microsoft.com/en-us/download/details.aspx?id=54920
go to above link and download the Microsoft Access Database engine Redistributable

then install it. Then you should see the driver

next go to SQL Script and run below

USE [MSDB]
GO

sp_configure 'show advanced options', 1
GO
RECONFIGURE WITH OverRide
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE WITH OverRide
GO

it will show

Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.
Configuration option 'Ad Hoc Distributed Queries' changed from 0 to 1. Run the RECONFIGURE statement to install.

now when you run the first SQL script you should be able to list out all the data.


UPDATE ON 2021 MAY 14:

if you get below message:
The OLE DB provider "Microsoft.ACE.OLEDB.16.0" for linked server "(null)" reported an error. Access denied

Try to run the MSSQL server using localAccount, rather that NTservices account




Monday, January 21, 2019

Microsoft Clear Script

Previously I have been using Microsoft Clear Script to add scripting capability to my .NET program.
Recently I upgraded to google V8 engine. If you are not familiar with ClearScript you can visit
https://github.com/Microsoft/ClearScript to take a look.

With V8 Engine the execution of javascript is pretty fast with some memories overhead.

Previously building V8 engine is really pain and not for faint heart.
Current is comes with NuGet Package. Just open Visual Studio 2015 or 2017, then search for clearscript.
 It should pop up then you can download it using NuGet.You need to save the project. It is just a few DLL files. Just use any project name will do.

After download just go to your user profile directory, default should be c:\users\%username%\.
Just do a search with "ClearScript" you should be able to locate the folder.  or you can search v8-x64.dll
all the dll files should be in the same folder. right click and open file location. copy all the DLL in the v8 folder, go back to on level above go to /lib and /net45 you will need to copy clearscript.dll and the xml also

put all those dll and xml file into /bin folder.

on ASP. NET please add below
system.web>
  <compilation>
    <assemblies>
      <remove assembly="ClearScriptV8-64" />
      <remove assembly="ClearScriptV8-32" />
    </assemblies>
  </compilation>
</system.web>
 Important: If Visual Studio is not installed on your deployment machine, you must install 32-bit and 64-bit Visual C++ Redistributable packages:
Visual C++ Redistributable for Visual Studio 2017 [x64] [x86]