How to: Push Data Using the RDA Object (Programmatically)
In this topic, you will learn how to push data from a Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) 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
Initialize a SqlCeRemoteDataAccess object and set the properties for the connection.
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess("https://www.adventure-works.com/sqlmobile/sqlcesa30.dll", "Data Source=MyDatabase.sdf");
Call the Push method, passing in the name of the local SQL Server Compact Edition 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 Edition 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 = <password>";
// Initialize RDA Object
//
SqlCeRemoteDataAccess rda = null;
try
{
// Try the Push Operation
//
rda = new SqlCeRemoteDataAccess(
"https://www.adventure-works.com/sqlmobile/sqlcesa30.dll",
"Data Source=MyDatabase.sdf");
rda.InternetLogin = "MyLogin";
rda.InternetPassword = "<password>";
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 = <password>"
' Initialize RDA Object
'
Dim rda As SqlCeRemoteDataAccess = Nothing
Try
' Try the Push Operation
'
rda = New SqlCeRemoteDataAccess( _
"https://www.adventure-works.com/sqlmobile/sqlcesa30.dll", _
"Data Source=MyDatabase.sdf")
rda.InternetLogin = "MyLogin"
rda.InternetPassword = "<password>"
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