2021年12月19日 星期日

always on 複本的CLR沒法用

sql sever 2019 15.0.4178.1做了1個複本的always on,設定手動容錯及可讀取。

問題來了,在複本DB可正常的讀取資料本,但無法使用CLR function

一般還原DB後都要執行以下語法,就可使用CLR方法(DB還原時trustworthy預設為off)

use testdb
go
alter database testdb set trustworthy on;
go
exec sp_changedbowner 'sa'
go

但複本唯讀根本也無法設定trustworthy 

google了大半天結論就是要failover後,將次要變主要後再執行設定。

巴特,我failover後次要變主要,然後順利地把次要的trustworthy設定為on ,並也測試了CLR方法可以正常使用

但再failover切回主要後,結果CLR方法還是沒法用,顯示的訊息就是沒設過trustworthy一樣.......

訊息 10314,層級 16,狀態 11,行 6
嘗試載入組件識別碼 65676 時,Microsoft .NET Framework 發生錯誤。可能是伺服器資源不足,或未信任組件。請重新執行查詢,或查看文件了解如何解決組件信任問題。如需此錯誤的詳細資訊:
System.IO.FileLoadException: 無法載入檔案或組件 'aesclr4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' 或其相依性的其中之一。 發生例外狀況於 HRESULT: 0x80FC80F1
System.IO.FileLoadException:
   於 System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   於 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   於 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
   於 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   於 System.Reflection.Assembly.Load(String assemblyString)

  


select name,is_trustworthy_on from sys.databases 

複本DB也is_trustworthy_on 確實是1了啊

期間也嚐試切換重建複本DB的組件assembly,但也是主要時一切正常,但failoverv變回複本時就沒法執行,不過訊息會變成

訊息 596,層級 21,狀態 1,行 4
工作階段為清除狀態,無法繼續執行。
訊息 0,層級 20,狀態 0,行 4
在目前的命令上發生嚴重錯誤。如果有任何結果,都必須捨棄。

Msg 596, Level 21, State 1, Line 0
Cannot continue the execution because the session is in the kill state.
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command.  The results, if any, should be discarded.

直到我把複本DB重啟後,再執行一次CLR方法,錯誤訊息才又會是嘗試載入組件識別碼 65676 時...

反覆的測試了幾次DB failover,似乎有那麼一次是部份CLR 方法是可用的, 但某次重做一次後就死光光了。

 always on failover倒覺得挺簡單的,就好像一個開關切換一下就成了,但CLR這關怎麼就過不了。

 google了大半天,找不到什麼資訊 .......挫折

 2021/12/27 建了一個簡單的DB裡面只有CLR 相關的assembly及方法, 結果不管主要還是次要複本如何切換,怎麼測怎麼OK....這樣看來正式環境上的AGG只能打掉重練了。


2022/09/25 最後主機整個打掉重建AGG後,CLR奇怪的問題就解決了。

沒有留言:

張貼留言

publish error allowDefinition='MachineToApplication'

一個老舊的aspx web form專案,調了一些功能建置成功,但進行部署時顯示以下錯誤。 在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為...