2011-04-20 25 views
0

Iam使用CertAdm.dll中的OpenConnection打開連接。C# - ICertView2 :: OpenConnection方法

像這樣: CERTADMINLib.CCertView connection = new CERTADMINLib.CCertViewClass();

我想知道我怎麼可以關閉此連接時蔭用它做?我沒有發現關閉連接的任何信息。

Thnx提前。

回答

0

這是很好的做法是使用「使用」的格局對於那些類型的連接:最後一個支柱連接部配置後

using (CERTADMINLib.CCertView connection = new CERTADMINLib.CCertViewClass()) 
    { 
    // do something ... 
    } 

+0

我會嘗試,日Thnx非常多。 – Lars 2011-04-20 16:11:57

+0

@Lars請upvote尋找答案;-) – wegginho 2011-04-21 06:32:26

+0

它不實現IDisposable。所以使用不能使用... – 2013-05-09 01:07:09

0

關閉連接這樣:

ICertView2 certView = null; 
IEnumCERTVIEWROW row = null; 
try 
{ 
    certView = new CCertView(); 
    certView.OpenConnection(_strCAConfig); 
    certView.SetResultColumnCount(1); 
    certView.SetResultColumn(certView.GetColumnIndex(0, "RequestID")); 
    row = certView.OpenView(); 
    row.Next(); 
    return row.GetMaxIndex(); 
} 
finally 
{ 
    Marshal.ReleaseComObject(row); 
    Marshal.ReleaseComObject(certView); 
}