共用方式為


SqlCeTransactionInProgressException Class

Occurs when an attempt is made to modify a database while another transaction is in progress.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

Syntax

'Declaration
Public Class SqlCeTransactionInProgressException
    Inherits SqlCeException
'Usage
Dim instance As SqlCeTransactionInProgressException
public class SqlCeTransactionInProgressException : SqlCeException
public ref class SqlCeTransactionInProgressException : public SqlCeException
public class SqlCeTransactionInProgressException extends SqlCeException
public class SqlCeTransactionInProgressException extends SqlCeException
Not applicable.

Example

Dim timeout As New TimeSpan(0, 0, 15) 'hours, minutes, seconds
Dim startTime As DateTime = DateTime.Now

While DateTime.Now - startTime < timeout
    Try
        Dim repl As New SqlCeReplication()

        repl.InternetUrl = "https://www.adventure-works.com/sqlmobile/sqlcesa30.dll"
        repl.Publisher = "myPublisher"
        repl.PublisherDatabase = "AdventureWorks"
        repl.PublisherSecurityMode = SecurityType.NTAuthentication
        repl.Publication = "AdventureWorks"
        repl.Subscriber = "Test"
        repl.SubscriberConnectionString = "Data Source='MyDatabase.sdf';Password='';"
        repl.Synchronize()
    Catch exInProgress As SqlCeTransactionInProgressException
        Thread.Sleep(3000)
        GoTo ContinueWhile1
    Catch exTimeout As SqlCeLockTimeoutException
        ' Add your own error-handling logic here
         GoTo ContinueWhile1
    Catch e As SqlCeException
        MessageBox.Show(e.Message)
    End Try
ContinueWhile1:
End While
TimeSpan timeout = new TimeSpan(0 /*hours*/, 0 /* minutes */ , 15 /*seconds*/);
DateTime startTime = DateTime.Now;

while (DateTime.Now - startTime < timeout)
{
    try
    {
        SqlCeReplication repl = new SqlCeReplication();

        repl.InternetUrl = "https://www.adventure-works.com/sqlmobile/sqlcesa30.dll";
        repl.Publisher = "myPublisher";
        repl.PublisherDatabase = "AdventureWorks";
        repl.PublisherSecurityMode = SecurityType.NTAuthentication;
        repl.Publication = "AdventureWorks";
        repl.Subscriber = "Test";
        repl.SubscriberConnectionString = "Data Source='MyDatabase.sdf';Password='';";
        repl.Synchronize();
    }
    catch (SqlCeTransactionInProgressException)
    {
        Thread.Sleep(3000);
        continue;
    }
    catch (SqlCeLockTimeoutException)
    {
        //add your own error-handling logic here
    }
    catch (SqlCeException e)
    {
        MessageBox.Show(e.Message);
    }
}

Inheritance Hierarchy

System.Object
   System.Exception
     System.SystemException
       System.Data.SqlServerCe.SqlCeException
        System.Data.SqlServerCe.SqlCeTransactionInProgressException

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0

.NET Compact Framework

Supported in: 2.0

See Also

Reference

SqlCeTransactionInProgressException Members
System.Data.SqlServerCe Namespace