2025年4月21日 星期一

[研究]System.Data.Entity.Core.OptimisticConcurrencyException 處理並行衝突 (EF6)

[研究]System.Data.Entity.Core.OptimisticConcurrencyException 處理並行衝突 (EF6)

2025-04-21

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19

********************************************************************************



System.Data.Entity.Core.OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). 
Entities may have been modified or deleted since entities were loaded. 
See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.


System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). 
Entities may have been modified or deleted since entities were loaded. 
See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions. 
---> System.Data.Entity.Core.OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). 
Entities may have been modified or deleted since entities were loaded. 
See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.
   於 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64 rowsAffected, UpdateCommand source)
   於 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   於 System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<>c.<Update>b__21_0(UpdateTranslator ut)
   於 System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
   於 System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
   於 System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__153_0()
   於 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   於 System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
   於 System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass148_0.<SaveChangesInternal>b__0()
   於 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   於 System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
   於 System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
   於 System.Data.Entity.Internal.InternalContext.SaveChanges()
   --- 內部例外狀況堆疊追蹤的結尾 ---
   於 System.Data.Entity.Internal.InternalContext.SaveChanges()
   於 System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   於 System.Data.Entity.DbContext.SaveChanges()
   於 System.Web.Providers.DefaultSessionStateProvider.ReleaseItemExclusive(HttpContext context, String id, Object lockId)
   於 System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs)
   於 System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   於 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   於 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


********************************************************************************

處理並行衝突 (EF6)
http://go.microsoft.com/fwlink/?LinkId=472540
https://learn.microsoft.com/zh-tw/ef/ef6/saving/concurrency?redirectedfrom=MSDN
Handling Concurrency Conflicts (EF6)
https://learn.microsoft.com/en-us/ef/ef6/saving/concurrency?redirectedfrom=MSDN

OptimisticConcurrencyException 類別
https://learn.microsoft.com/zh-tw/dotnet/api/system.data.optimisticconcurrencyexception?view=netframework-4.8.1
發生開放式同步存取違規時擲回的例外狀況。

https://learn.microsoft.com/en-us/dotnet/api/system.data.optimisticconcurrencyexception?view=netframework-4.8.1
The exception that is thrown when an optimistic concurrency violation occurs.

********************************************************************************

(完)

相關





2025年4月18日 星期五

[研究] Ubuntu 25.04 (非LTS) Desktop Linux 安裝

[研究] Ubuntu 25.04 (非LTS) Desktop Linux 安裝

2025-04-18

官方網站

https://www.ubuntu-tw.org/

https://releases.ubuntu.com/25.04

24.04 是 LTS 版,但 24.10 不是。25.04 於2025-04-17釋出,也不是 LTS。

Click 圖片可以看100%原尺寸圖,安裝不難,只是留個紀錄。






















































https://help.ubuntu.com/



(完)

相關

[研究] Ubuntu 25.04 (非LTS) Desktop Linux 安裝
https://shaurong.blogspot.com/2025/04/ubuntu-2504-lts-desktop-linux.html

[研究] Ubuntu 24.10 (非LTS) Desktop Linux 安裝
https://shaurong.blogspot.com/2024/10/ubuntu-2410-lts-desktop-linux.html

[研究] Ubuntu 24.04 LTS Desktop Linux 安裝
https://shaurong.blogspot.com/2024/04/ubuntu-2404-lts-desktop-linux.html

[研究] Ubuntu 23.10 (非LTS) Desktop Linux 安裝
https://shaurong.blogspot.com/2023/11/ubuntu-2310-lts-desktop-linux.html

[研究] Ubuntu 23.04 (非LTS) Desktop Linux 安裝
http://shaurong.blogspot.com/2023/04/ubuntu-2304-lts-desktop-linux.html

[研究] Ubuntu 22.10 Desktop Linux 安裝
https://shaurong.blogspot.com/2022/10/ubuntu-2210-desktop-linux.html

[研究] Ubuntu 18.04 Desktop x64 LTS 安裝 VMware Tools-10.2.5-8068393.tar.gz
https://shaurong.blogspot.com/2018/05/ubuntu-1804-desktop-x64-lts-vmware.html

[研究] Ubuntu 22.04 LTS Desktop Linux 安裝
https://shaurong.blogspot.com/2022/05/ubuntu-2210-lts-desktop-linux.html

[研究] Ubuntu 21.10 Desktop Linux 安裝
https://shaurong.blogspot.com/2021/10/ubuntu-2110-desktop-linux.html

[研究] Ubuntu 21.04 Live Server Linux 安裝
https://shaurong.blogspot.com/2021/07/ubuntu-2104-live-server-linux.html

Index of /ubuntu-releases/
https://ftp.ubuntu-tw.org/ubuntu-releases/

Ubuntu release cycle | Ubuntu
https://ubuntu.com/about/release-cycle

BionicBeaver/ReleaseSchedule - Ubuntu Wiki
https://wiki.ubuntu.com/BionicBeaver/ReleaseSchedule

Releases - Ubuntu Wiki
https://wiki.ubuntu.com/Releases


2025年4月17日 星期四

[研究] OWASP Dependency Check 12.1.0元件依賴關係檢查工具(失敗)

[研究] OWASP Dependency Check 12.1.0元件依賴關係檢查工具(失敗)

2025-04-17

OWASP Dependency Check
https://www.owasp.org/index.php/OWASP_Dependency_Check

官方簡報
http://jeremylong.github.io/DependencyCheck/general/dependency-check.pptx


https://github.com/dependency-check/DependencyCheck/releases/download/v12.1.0/dependency-check-12.1.0-release.zip

Dependency Check 是一種「軟件組成分析工具」 (Software Composition Analysis,SCA) ,它會檢查軟體組成,以及可能漏洞。它使用「通用平台枚舉」(Common Platform Enumeration,CPE)取得軟體組成相關資訊。如果找到,它將產生一個報告,提供「常見漏洞和披露」 Common Vulnerability and Exposure,CVE) 超連結。

注意,結果有可能誤判,此程式對  Java 程式比 .NET 程式合用,對 .NET程式可能誤判。

執行需要 Java JRE,否則不能執行。

下載 OpenJDK Microsoft組建



C:\>C:\dependency-check\bin\dependency-check.bat --project "WebApplication1" --scan "C:\Code\WebApplication1\WebApplication1\bin" --out "C:\Temp"
'java' 不是內部或外部命令、可執行的程式或批次檔。

C:\>

敝人安裝 ( JAVA_HOME 可以不用勾選,預設也沒勾)
注意,Java安裝後,要開啟新的「命令提示字元」才能用

C:\>java --version
openjdk 17.0.13 2024-10-15 LTS
OpenJDK Runtime Environment Microsoft-10376486 (build 17.0.13+11-LTS)
OpenJDK 64-Bit Server VM Microsoft-10376486 (build 17.0.13+11-LTS, mixed mode, sharing)

C:\>



C:\dependency-check\bin>dependency-check.bat -v
Dependency-Check Core version 12.1.0

C:\dependency-check\bin>dependency-check.bat
usage: Dependency-Check Core [--advancedHelp] [--disableVersionCheck]
       [--enableExperimental] [--exclude <pattern>] [-f <format>]
       [--failOnCVSS <score>] [-h] [--junitFailOnCVSS <score>] [-l <file>]
       [-n] [--nvdApiKey <apiKey>] [-o <path>] [--prettyPrint] [--project
       <name>] [-s <path>] [--suppression <file>] [-v]

Dependency-Check Core can be used to identify if there are any known CVE
vulnerabilities in libraries utilized by an application. Dependency-Check
Core will automatically update required data from the Internet, such as
the CVE and CPE data files from nvd.nist.gov.

    --advancedHelp              Print the advanced help message.
    --disableVersionCheck       Disables the dependency-check version
                                check
    --enableExperimental        Enables the experimental analyzers.
    --exclude <pattern>         Specify an exclusion pattern. This option
                                can be specified multiple times and it
                                accepts Ant style exclusions.
 -f,--format <format>           The report format (HTML, XML, CSV, JSON,
                                JUNIT, SARIF, JENKINS, GITLAB or ALL). The
                                default is HTML. Multiple format
                                parameters can be specified.
    --failOnCVSS <score>        Specifies if the build should be failed if
                                a CVSS score above a specified level is
                                identified. The default is 11; since the
                                CVSS scores are 0-10, by default the build
                                will never fail.
 -h,--help                      Print this message.
    --junitFailOnCVSS <score>   Specifies the CVSS score that is
                                considered a failure when generating the
                                junit report. The default is 0.
 -l,--log <file>                The file path to write verbose logging
                                information.
 -n,--noupdate                  Disables the automatic updating of the
                                NVD-CVE, hosted-suppressions and RetireJS
                                data.
    --nvdApiKey <apiKey>        The API Key to access the NVD API.
 -o,--out <path>                The folder to write reports to. This
                                defaults to the current directory. It is
                                possible to set this to a specific file
                                name if the format argument is not set to
                                ALL.
    --prettyPrint               When specified the JSON and XML report
                                formats will be pretty printed.
    --project <name>            The name of the project being scanned.
 -s,--scan <path>               The path to scan - this option can be
                                specified multiple times. Ant style paths
                                are supported (e.g. 'path/**/*.jar'); if
                                using Ant style paths it is highly
                                recommended to quote the argument value.
    --suppression <file>        The file path to the suppression XML file.
                                This can be specified more then once to
                                utilize multiple suppression files
 -v,--version                   Print the version information.

C:\dependency-check\bin>

注意 Dependency Check 使用線上資料庫,所以必須連上 Internet 才行。


dependency-check.bat --project "'方案/專案名稱" --scan "bin目錄"  --out  "輸出檔案 or 輸出檔案目錄"


【測試】

WebApplication1 方案是敝人另外用 Visual Studio 2019建立的。


非常慢,隔了一陣子出現 Downloaded 訊息

C:\dependency-check\bin>dependency-check.bat --project "WebApplication1" --scan  "C:\Code\WebApplication1\WebApplication1\bin" --out "C:\Temp"
[INFO] Checking for updates
[WARN] An NVD API Key was not provided - it is highly recommended to use an NVD API key as the update can take a VERY long time without an API Key
[INFO] NVD API has 289,264 records in this update
[INFO] Downloaded 10,000/289,264 (3%)
[INFO] Downloaded 20,000/289,264 (7%)
[INFO] Downloaded 30,000/289,264 (10%)
[INFO] Downloaded 40,000/289,264 (14%)

...(略)

[ERROR] Failed to process CVE-2011-3380
java.lang.NullPointerException: Cannot invoke "org.apache.commons.dbcp2.BasicDataSource.getConnection()" because "this.connectionPool" is null
        at org.owasp.dependencycheck.data.nvdcve.DatabaseManager.getConnection(DatabaseManager.java:576)
        at org.owasp.dependencycheck.data.nvdcve.CveDB.updateOrInsertVulnerability(CveDB.java:1173)
        at org.owasp.dependencycheck.data.nvdcve.CveDB.updateVulnerability(CveDB.java:1098)
        at org.owasp.dependencycheck.data.update.nvd.api.NvdApiProcessor.updateCveDb(NvdApiProcessor.java:119)
        at org.owasp.dependencycheck.data.update.nvd.api.NvdApiProcessor.call(NvdApiProcessor.java:96)
        at org.owasp.dependencycheck.data.update.nvd.api.NvdApiProcessor.call(NvdApiProcessor.java:40)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:840)
[ERROR] Failed to process CVE-2011-3627
java.lang.NullPointerException: Cannot invoke "org.apache.commons.dbcp2.BasicDataSource.getConnection()" because "this.connectionPool" is null
        at org.owasp.dependencycheck.data.nvdcve.DatabaseManager.getConnection(DatabaseManager.java:576)
        at org.owasp.dependencycheck.data.nvdcve.CveDB.updateOrInsertVulnerability(CveDB.java:1173)
        at org.owasp.dependencycheck.data.nvdcve.CveDB.updateVulnerability(CveDB.java:1098)
        at org.owasp.dependencycheck.data.update.nvd.api.NvdApiProcessor.updateCveDb(NvdApiProcessor.java:119)
        at org.owasp.dependencycheck.data.update.nvd.api.NvdApiProcessor.call(NvdApiProcessor.java:96)
        at org.owasp.dependencycheck.data.update.nvd.api.NvdApiProcessor.call(NvdApiProcessor.java:40)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:840)

C:\dependency-check\bin>

【加上 NVD API Key 測試】


非常慢,隔了一陣子出現 Downloaded 訊息

C:\>C:\dependency-check\bin\dependency-check.bat --project "WebApplication1" --scan  "C:\Code\WebApplication1\WebApplication1\bin" --out "C:\Temp" --nvdApiKey 申請得到的Key
[INFO] Checking for updates
[INFO] NVD API has 289,459 records in this update
[INFO] Downloaded 10,000/289,459 (3%)
[INFO] Downloaded 20,000/289,459 (7%)
[INFO] Downloaded 30,000/289,459 (10%)
[INFO] Downloaded 40,000/289,459 (14%)
[INFO] Downloaded 50,000/289,459 (17%)
[INFO] Downloaded 60,000/289,459 (21%)
[INFO] Downloaded 70,000/289,459 (24%)
[INFO] Downloaded 80,000/289,459 (28%)
[INFO] Downloaded 90,000/289,459 (31%)
[INFO] Downloaded 100,000/289,459 (35%)
[INFO] Downloaded 110,000/289,459 (38%)
[INFO] Downloaded 120,000/289,459 (41%)
[INFO] Downloaded 130,000/289,459 (45%)
[INFO] Downloaded 140,000/289,459 (48%)
[INFO] Downloaded 150,000/289,459 (52%)
[INFO] Downloaded 160,000/289,459 (55%)
[INFO] Downloaded 170,000/289,459 (59%)
[INFO] Downloaded 180,000/289,459 (62%)
[INFO] Downloaded 190,000/289,459 (66%)
[INFO] Downloaded 200,000/289,459 (69%)
[INFO] Downloaded 210,000/289,459 (73%)
[INFO] Downloaded 220,000/289,459 (76%)
[INFO] Downloaded 230,000/289,459 (79%)
[INFO] Downloaded 240,000/289,459 (83%)
[INFO] Downloaded 250,000/289,459 (86%)


測試2次,隔天看停到 Download,暫時放棄、、、

(待續)

相關

[研究] OWASP Dependency-Check 9.0.6 元件依賴關係檢查工具
https://shaurong.blogspot.com/2023/12/owasp-dependency-check-906.html

[研究] OWASP Dependency Check 6.2.2 元件依賴關係檢查工具https://shaurong.blogspot.com/2021/08/owasp-dependency-check-622.html

[研究] OWASP Dependency Check 4.0.0 元件依賴關係檢查http://shaurong.blogspot.com/2018/12/owasp-dependency-check-400.html