Powershell 2.0을 사용하여 사용자 지정 .Net 2.0 어셈블리 집합과 상호 작용하여 현재 작업을 자동화합니다. dll에 필요한 모든 dll을로드하고 dal 메서드를 호출하여 System.Data.SqlDataReader를 검색합니다. 동일한 사용자 지정 어셈블리의 생성자에 SqlDataReader를 전달하면 "판독기가 닫힐 때 HasRows를 호출하는 잘못된 시도"가 발생합니다. 예외.Powershell 2.0 - 함수에 전달할 때 SqlDataReader가 닫힙니다.
코드 샘플 :
dir D:\stuff\*.dll | foreach { [Reflection.Assembly]::LoadFrom($_.FullName) } | out-null
[CustomAssembly.DataConfig]::ConnectionString = "Valid Connection String"
$reader=[CustomAssembly.DAL.Thing]::Get(123)
new-object CustomAssembly.BusinessObjects.Thing($reader)
은 $ 독자가 열려, 그리고 나는 것 생성자를 호출하기 전에, 데이터가 있습니다.
나는 뭔가를 놓치고 있어야하지만 나는 그것이 무엇인지 잘 모릅니다.
편집 1
$ 판독기 표시 읽고, 파워 쉘 또는 어셈블리에서,이 함수에 전달 언제 폐쇄한다. 이것을 막을 수있는 방법이 있습니까?
편집 2 : 다시
파워 쉘 자동 풀림 타격
How to stop PowerShell from unpacking an Enumerable object?
Strange behavior in PowerShell function returning DataSet/DataTable
단일 소자 어레이에 결과를 배치하여 다음 수정 코드 샘플 작동하므로 자동 언 롤링은 SqlDataReader에 영향을주지 않습니다. "$ reader ="문 다음에 단일 쉼표가 있음에 유의하십시오. 그것은 오타가 아닙니다.
dir D:\stuff\*.dll | foreach { [Reflection.Assembly]::LoadFrom($_.FullName) } | out-null
[CustomAssembly.DataConfig]::ConnectionString = "Valid Connection String"
$reader=,[CustomAssembly.DAL.Thing]::Get(123)
new-object CustomAssembly.BusinessObjects.Thing($reader)
SqlDataReader의 경우 인 것 같습니다. 그걸 막을 수있는 방법이 있습니까? – Jared314
그것을 막을 방법이 없기 때문에 다른 배열로 포장해야합니다. – Jared314