How to: Push Data by Using the RDA Object (Programmatically)

In this topic, you will learn how to push data from a Microsoft SQL Server Compact 3.5 (SQL Server Compact 3.5) database to a Microsoft SQL Server database by using the SqlCeRemoteDataAccess class. For more information about using the SqlServerCe namespace, see the SqlServerCe namespace reference documentation.

To push data by using remote data access

  1. Initialize a SqlCeRemoteDataAccess object and set the properties for the connection.

    SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess("https://www.adventure-works.com/sqlmobile/sqlcesa35.dll", "Data Source=MyDatabase.sdf");
    
  2. Call the Push method, passing in the name of the local SQL Server Compact 3.5 table from which to push the data and the connection string to the SQL Server database. You can also specify the batch option to use.

    rda.Push("MyLocalTable", rdaOleDbConnectString, RdaBatchOption.BatchingOn);
    

Example

This sample shows how to push data from the MyLocalTable table on a SQL Server Compact 3.5 database to the AdventureWorks database on an instance of SQL Server named MySqlServer.

string rdaOleDbConnectString = @"Provider=SQLOLEDB; Data Source=MySqlServer;
    Initial Catalog=AdventureWorks; User Id=username;
    Password = <enterStrongPasswordHere>";

        // Initialize RDA Object
        //
        SqlCeRemoteDataAccess rda = null;

        try
        {
            // Try the Push Operation
            //
            rda = new SqlCeRemoteDataAccess(
                "https://www.adventure-works.com/sqlmobile/sqlcesa35.dll",
                "Data Source=MyDatabase.sdf");

            rda.InternetLogin = "MyLogin";
            rda.InternetPassword = "<enterStrongPasswordHere>";

            rda.Push("MyLocalTable", rdaOleDbConnectString, RdaBatchOption.BatchingOn);

            // or, try this overload:
            //
            // rda.Push("MyLocalTable", rdaOleDbConnectString);
        }
        catch (SqlCeException)
        {
            // Handle errors here
            //
        }
        finally
        {
            // Dispose of the RDA Object
            //
            rda.Dispose();
        }
Dim rdaOleDbConnectString As String = _
 "Provider=SQLOLEDB; "Data Source=MySqlServer;Initial Catalog=AdventureWorks; "
            "User Id=username;Password = <enterStrongPasswordHere>"

        ' Initialize RDA Object
        '
        Dim rda As SqlCeRemoteDataAccess = Nothing

        Try
            ' Try the Push Operation
            '
            rda = New SqlCeRemoteDataAccess( _
                "https://www.adventure-works.com/sqlmobile/sqlcesa35.dll", _
                "Data Source=MyDatabase.sdf")

            rda.InternetLogin = "MyLogin"
            rda.InternetPassword = "<enterStrongPasswordHere>"

            rda.Push("MyLocalTable", rdaOleDbConnectString, RdaBatchOption.BatchingOn)

            ' or, try this overload:
            '
            ' rda.Push("MyLocalTable", rdaOleDbConnectString)

        Catch
            ' Handle errors here
            '
        Finally
            ' Dispose of the RDA Object
            '
            rda.Dispose()
        End Try

See Also

Other Resources

Introducing Remote Data Access
Pushing Data from Client to Server

Help and Information

Getting Assistance (SQL Server Compact 3.5 Service Pack 1)