SQL Server CE, SQL ????? 2005 ??????? ???????, ?? SQL Server 2005 ?????? ??????? ?? dispose ???? ?? ??? ??????? ?????????? ?????? ?? ????????

???? ?????? ???? ??????
???? ID: 834279 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ???? ????? ???? ?? ?? ?? dispose ???? ?? ??? ??????? ?????? Microsoft Visual Studio ?? ????? ???? ???? ?? ??????????? ??? ???????? ???? ???? ???????? Microsoft SQL Server 2000 Windows CE ??????? ???, Microsoft SQL Server 2005 ??????? ???????, ?? SQL Server 2005 ?????? ??????? ???????? ?????? ?? Microsoft ?? ????? ?????Framework ??? ????????? ???

???? ???????

.??? ????????? ????? ???? ???????, SQL ????? CE, SQL ????? 2005 ??????? ???????, ?? SQL Server 2005 ?????? ??????? ?? ??? ?????? ??????? ????, ?? ?????? ???? ??. SqlCeCommand ????, SqlCeConnection ????, ?? SqlCeDataReader ????? ?? ?? ?????? ??? ?? ?????????? ?? ????? ?? ???? ??? SQL Server CE, SQL ????? 2005 ??????? ???????, ?? SQL Server 2005 ?????? ??????? ??????? ??? ?? ?????? ?? Microsoft Windows CE ??? ?? ??? ??? ?????? ???? ?? ???, ??????? ???????? ???????? ???????, ?? ?????? ?????? ?? ???? ???? ???????? ?? ?????? ???? ???, ?? ???????? ???

?????? ?? ?????? ?? ?????? ?? ??? ?? ????? ??????? ?? ????? ?? ???? ??? ' % ws ' ?? ??????? ?????????

??? Microsoft ??????? ???? ?? ?? ?? ?? ????? Close() ???? ?? Dispose() ???? ?? ????? ?????? ???? ?? ??? ?????? ?????? ?? ??? ?? ???????? ?????? ?? ??? ??????? ???????
  • ?? ????? Close() ???? ?? Dispose() ????? ??? ?? ??? ??????? SQL Server CE ?? ???, SQL Server 2005 ??????? ???????, ?? SQL Server 2005 ?????? ??????? ?? ??? ???????? ?? ??????????? IDisposable ????????? ??????? ?? ??????? ???????????. IDisposable ?? ???????? Dispose() ?? ???? ' IDisposable ???????? ?? ???? ??? ???? ?? ???? ?? ??? ?????? ?????? ?? ??? ???????? ???????? ???

    ?? ??????? ?? ??????????? ?? Close() ???? ?? ???? Dispose() ????? ?????, ?? ?? ?? ??? ?? ???? ??? Close()???? ?? Dispose() ?????? ?? ?????? ?? ?????? ?? ??? ???? ???????? ??? ???????, ?? ???, ?? Close() ????, ?? ??? ???? ??? ??? ???? Dispose() ?????

    ?????? ?? ???, ?? ?? ?? ????? SqlCeDataAdapter ???? ???? dataset ?? ????????? ???? ?? ???, ?? ?????? ??? ?? ??? ?? dispose ???? ???? ?? ???????SqlCeCommand ?????????? ?? ??? ???? ?????? ?? ???????????? ????, ?????? ????, ???????? ???? ?? ????? ????? ?? ????? ??? ???? ?? ???? ?? ????? ?? ???? ??????? ???? ?? ??? ?????? ????? ???:
     SqlCeConnection conn = null; 
     try
     {
    	 conn = new SqlCeConnection(<ConnectionString>);
    	 conn.Open(); 
    	// Work with the connection object
    }
    catch (Exception en)
    {
    	// Handle the exception or rethrow it
    }
    finally
    {
    	// Always release the native references in the finally clause
    	// The statements in finally clause are guaranteed to run
    
    	if (null != conn) conn.Close(); 
    } 
  • ?? ????? Collect() ?? ???? GC ?? ?????? Collector ?????

    ??? Extremely ?? ????? ?? ??? ??? ?? Collect() ?? ???? GC ?? ?????? Collector ????? ?????, Microsoft ?? ?? ?? ????? ???? ?? Collect()?? ???? GC ???? ?? ??? ???? ?????, ?? ?? ?????? Collector ?????

    ??? ???? ?? ??? ????? ??? ???? ?? ????? ???? Collect()' % ws ' ?? ?? ?????? Collector ???? ????????? ??? ????:
    try
    {
           SqlCeConnection conn = null;
           conn = new SqlCeConnection(<ConnectionString>);
           conn.Open(); 
     
           // The connection instance goes out of scope and effectively loses native references here
           // The conn object is only disposed of when the Garbage Collector starts finalizing objects,
           // but this only occurs under memory pressure.
           // If many objects are allocated like this, the performance of the program decreases.
    }
    catch (Exception en)
    {
           // Handle the exception or rethrow it
    }
    finally
    { 
           // If GC.Collect() is called, the Garbage Collector is forced to run all the finalizers in the finalization queue. 
           // Therefore, the connection instance that was previously lost is disposed of here by the Collect method of the GC Garbage Collector class. 
           // By putting this in the finally clause we guarantee it will always be executed even if the exception is rethrown
           
           GC.Collect();
    }
     
    ?? ?? ???? ??? ???? ????? ????? ??? ??? ???? ?? ????? ???? ???, ?? ???? ?????? ??? ?? ??????? ???? ?? ??? ???? ??Collect() ' % ws ' ?? ?? ?????? Collector ???????

??????

?? ???? ??? ???? ??????? ?? ??? IDisposable ????????, ?? ???? ????? Microsoft ??? ????:
.aspx http://msdn2.microsoft.com/en-us/library/system.idisposable (vs.71)
?? ???? ??? ???? ??????? ?? ??? ' GC.Collect() ????, Microsoft ?? ????? ??? ???? ?? ????:
.aspx http://msdn2.microsoft.com/en-us/library/aa903907 (VS.71)
?? ???? ??? ???? ??????? ?? ??? ' SqlCeConnection.Close ????, Microsoft ?? ????? ??? ?? ???? ????:
.aspx http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlceconnection.close (vs.71)
???? ??????? ?? ???, Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
824462??? ?? ???? SqlCeDataAdapter ???????? ?? ????? SqlCeCommand ???????? ???????? ??? ?? disposed ??? ??? ????
326164 Dumpmem ?????? ??? PC 2002 ?? ??????? ??? ????? ?? ????? ?? ???
827837 ?????: ?? ?? SqlCeDataReader ???????? ???? ???, ?? SQL ????? CE ??????? ?????? ???? ???? ????

???

???? ID: 834279 - ????? ???????: 13 ??????? 2011 - ??????: 1.0
???? ???? ???? ??:
  • Microsoft .NET Compact Framework
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Academic Edition
  • Microsoft SQL Server 2005 Compact Edition
??????: 
kbgarbagecollect kbmemory kbappdev kbcodesnippet kbcode kbinfo kbmt KB834279 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:834279

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com