2025年4月29日 星期二

VS CODE離線安裝套件方式

VS CODE可攜式安裝下載 https://code.visualstudio.com/download,點選windows 下.zip x64下載VSCode-win32-x64-1.99.3.zip,解壓縮到某目錄。

安裝離線版套件,例如安裝powershell套件,

先安裝最新版 powershell ,進入https://github.com/PowerShell/PowerShell

在右方Releases 會顯示最新版本號,點選進入去下載 PowerShell-7.5.1-win-arm64.msi


再到 https://marketplace.visualstudio.com/ 找需要的安裝檔vsix。


導引到https://github.com/PowerShell/vscode-powershell 一樣在右方Releases 會顯示最新版本號,點進去下載powershell-2025.0.0.vsix


開啟code.exe ,點選左方sidebar 的Extensions, 在視窗右上方 ... 選取 install from VSIX ...,就可以離線安裝所需的套件了。

心得:powershell 7功能較多,雖無像powershell 5 自帶ISE,但使用VS CODE套件也足以滿足所需,重點是還可以debug,十分方便。



2025年4月16日 星期三

tsql 不用unpivot 將columns轉rows

有個需求需要將多一筆資料的多欄位值轉成多列資料

之前都使用unpivot,試了一下直接用outer apply就可達成,十分好用。

其中concat 會自動處理null 為空值再串聯文字,所以也不用判斷isnull(col1,'')了。

declare @tab table (col1 nvarchar(10),col2 nvarchar(10),col3 nvarchar(10),col4 nvarchar(10))

insert into @tab values

('A','X','Y','Z'),

('B','X','Y',null),

('A','1','2','')

select distinct  col1,y.value

from @tab outer apply   (select * from string_split(concat(col2,',',col3,',',col4),',') where value > '') y

2024年9月27日 星期五

自動記錄滑鼠點選操作

為了一個需求,需要人工去點選幾個滑鼠的點選行為,找了幾種工具,覺得GS Auto Clicker最實用,極符合我的需求,尤其是多個固定位置的button點擊,解決了一個很耗時間的工作。

最後設定完預設hotkey F8為啟用鍵,就可以開始自動做工了。再按F8結束工作。

GS Auto Clicker - Free - download for Windows (digitaltrends.com) 








2024年9月11日 星期三

和SSL連線有關的設定

HTTPS連線,不管是在寫sql clr或者powershell,每次遇到以下二類SSL錯誤,都忘了要改啥。這次記錄下,以後可以參考。

System.Net.WebException: 基礎連接已關閉: 接收時發生未預期的錯誤。 ---> System.ComponentModel.Win32Exception: 用戶端和伺服器無法溝通,因為它們沒有公用的演算法

加入以下

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12| SecurityProtocolType.Tls13;

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: 基礎連接已關閉: 無法為 SSL/TLS 安全通道建立信任關係。 ---> System.Security.Authentication.AuthenticationException: 根據驗證程序,遠端憑證是無效的。

加入以下:

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

順便再加一段sql clr assembly,單純的呼叫GET方法 WEB URL,回傳respone內容。


2024年8月26日 星期一

無法使用Database Mail

設定Database Mail時,顯示

Database Mail depends on Service Broker. Service Broker is not active in msdb. Do you want to activate Service Broker in msdb? If you do not activate Service Broker, Database Mail will queue e-mail messages, but will not be able to deliver the messages.

select is_broker_enabled from sys.databases where name = 'msdb';
回傳0,確實沒啟動。

ALTER DATABASE msdb SET ENABLE_BROKER ;

等了好久沒反應。

參考以下重建

https://learn.microsoft.com/zh-tw/troubleshoot/system-center/scom/troubleshoot-sql-server-service-broker-issues

use master
go

ALTER DATABASE msdb SET SINGLE_USER WITH ROLLBACK IMMEDIATE ALTER DATABASE msdb SET NEW_BROKER WITH ROLLBACK IMMEDIATE ALTER DATABASE msdb SET MULTI_USER go ALTER DATABASE msdb SET SINGLE_USER WITH ROLLBACK IMMEDIATE ALTER DATABASE msdb SET ENABLE_BROKER ALTER DATABASE msdb SET MULTI_USER go

2024年8月16日 星期五

ReportViewer 工具列顯示中文

VS專案中要升級舊版的report viewer,已經不用再去安裝runtime,直接以NuGet方式安裝Microsoft.ReportingServices.ReportViewerControl.WebForms  150.1652.0 ,但部署後,工具列都是英文沒有中文。

但在bin下其實有本地化的目錄zh-CHT 所以應該有支援多語系,在bing和google了半天都找不到想要的,覺得這二個搜尋引擎好像愈來愈難找到想要的資訊,是我的錯覺嗎???

後來想到用保哥很推薦的felo search(https://felo.ai/),還真的沒讓我失望耶。

輸入了 Microsoft.ReportingServices.ReportViewerControl.WebForms zh-CHT  詳列了做法。主要是在web.config加入以下設定。

<configuration>

  <system.web>

    <globalization culture="zh-CHT" uiCulture="zh-CHT" />

  </system.web>

</configuration>

將zh-CHT 目錄下的dll加入專案參考後,重新部署,工具列就出現中文了。


2024年8月5日 星期一

SQL AGENT無法啟動 無效的物件名稱 'syssubsystems'

有一天一台SQL 2019 主機安裝CU27後,SQL AGENT無法啟動,查看SQLAGENT.OUT記錄檔錯誤如下

2024-08-06 12:00:08 - ! [298] SQLServer 錯誤: 208,無效的物件名稱 'syssubsystems'。 [SQLSTATE 42S02] (ConnCacheSubsystems)

2024-08-06 12:00:08 - ! [449] 無法列舉子系統 (原因: 無效的物件名稱 'syssubsystems'。 [SQLSTATE 42S02] (錯誤 208))

再安裝CU28也是一樣問題無法啟動。

於是找了另外一台正常的DB查看,確實有syssubsystems這個資料表存在。

直接轉出create語法在有問題的那台DB把資料表建起來,重啟SQL AGENT服務就正常了。

CREATE TABLE [dbo].[syssubsystems](

[subsystem_id] [int] NOT NULL,

[subsystem] [nvarchar](40) NOT NULL,

[description_id] [int] NULL,

[subsystem_dll] [nvarchar](255) NULL,

[agent_exe] [nvarchar](255) NULL,

[start_entry_point] [nvarchar](30) NULL,

[event_entry_point] [nvarchar](30) NULL,

[stop_entry_point] [nvarchar](30) NULL,

[max_worker_threads] [int] NULL

) ON [PRIMARY]

GO

重啟後,這個資料表就會自動長出一些資料。

看了二篇文章似乎都跟msdb有做什麼變動造成的。回想一下為什麼有這個錯,我有改過msdb嗎?? 好像也沒有...

https://www.dbaservices.com.au/the-ssis-subsystem-failed-to-load/

The problem is most likely that the location of your SQL Server installation directory differs from that of the old serve

https://byronhu.wordpress.com/2011/07/04/sql-agent-job-%E6%9A%AB%E5%81%9Csuspend/

因為從原來全部安裝在 C:\ 的 SQL Server 備份 msdb 後,restore 到安裝在 D:\ 的 SQL Server,除要注意 SQL Server 的 Build No 外,若有  Job 呼叫到外部子系統(例如 SSIS、Replication…等),也要一併注意 msdb.dbo.syssubsystems 的設定

二篇都說到執行,但我是連這個資料表都沒有,就直接重建了。
use msdb
go
delete from msdb.dbo.syssubsystems
exec msdb.dbo.sp_verify_subsystems 1
go

VS CODE離線安裝套件方式-續

去年 vscode離線安裝 powershell nupkg 今年在一台無外網的 windwos 2025上安裝時遇到了powershell版本一直讀取到了5.1的版本,鬼打牆了一下午,在VM還原重測測了好幾回,應該是可行了。 將下載到的免安裝powershell 解壓縮到...