Microsoft Corporation
January 2007
Applies to:
Microsoft Visual Studio 2005
Microsoft SQL Server 2005 Compact Edition
Summary: In this tutorial, you will learn how to create a Microsoft Windows Forms application using Microsoft Visual C#.NET that synchronizes data between a Microsoft SQL Server 2005 database and a Microsoft SQL Server 2005 Compact Edition database using Microsoft SQL Server 2005 Compact Edition Remote Data Access (RDA). (48 printed pages)
Tutorial Objective
Conclusion
Appendix A: Setting Up Your Computer
This tutorial uses Microsoft IIS for Microsoft Windows XP Professional. Be sure that the IIS component is installed. For more information, see Appendix A.
This tutorial requires Microsoft Visual Studio 2005 Standard, Professional, or Team System Edition. It will not work with any of the Express Editions. If you do not have the correct edition of Visual Studio 2005, find out how you can acquire it from the Visual Studio 2005 Developer Center.
Find out how to acquire a copy at the SQL Server Developer Center.
This tutorial uses the Northwind sample database that was provided with previous versions of SQL Server. If you do not have this database, a copy has been provided with this tutorial's installation. See Appendix A for instructions on attaching the database to your SQL Server.
Before performing this tutorial, you should have already performed the steps in the tutorial titled "Configuring Internet Information Services for SQL Server 2005 Compact Edition Remote Data Access and Merge Replication," which instructs you on how to configure your computer's IIS for SQL Server 2005 Compact Edition synchronization.
In order to save time in this tutorial, you can quickly insert code snippets that have been prepared for you. See Appendix A to install the code snippets on your computer.
200
1 hour
In this tutorial, you will learn how to create a Microsoft Windows Forms application using Microsoft Visual C#.NET that synchronizes data between a Microsoft SQL Server 2005 database and a Microsoft SQL Server 2005 Compact Edition database using Microsoft SQL Server 2005 Compact Edition Remote Data Access (RDA).
In this tutorial, you will perform the following exercise:
In this exercise, you will learn how to create a Windows Forms application using Visual C#.NET that synchronizes data between a SQL Server 2005 database and a SQL Server 2005 Compact Edition database using SQL Server 2005 Compact Edition Remote Data Access.
Note Before performing this exercise, you should have already performed the steps in the tutorial titled "Configuring Internet Information Services for SQL Server 2005 Compact Edition Remote Data Access and Merge Replication," which instructs you on how to configure your computer's IIS for SQL Server 2005 Compact Edition synchronization.
Note Depending on your Visual Studio configuration, Visual C# might appear under Other Languages.
Note You can create the project in the Location of your choice.
Figure 1. Creating the RDADemo project (Click on the picture for a larger image)
Visual Studio creates a new project and opens Form1 in the form designer. Because one of the goals of this tutorial is to show server-hosted SQL Server 2005 data and a local client's SQL Server Compact Edition data at the same time, you will use a splitter control to show both views on the same screen.
Figure 2. Expanding Containers to reveal the SplitContainer control
Figure 3. Adding the splitContainer1 control to Form1
Figure 4. Select horizontal splitter orientation
Figure 5. Selecting Form1 in the Properties pane drop-down list of controls
Form1 should now look like Figure 6.
Figure 6. Form1's modified layout
The top panel will contain the SQL Server data, and the bottom panel will contain the SQL Server Compact Edition data. Before you can display the SQL Server data in the form, you must add a project data source for the SQL Server data.
Figure 7. Choosing a data-source type
Note If the Choose Data Source dialog box appears instead of the Add Connection dialog box, continue to the next step.
Note If the Choose Data Source dialog box appeared instead of the Add Connection dialog box, you must press the Continue button.
Figure 8. Choosing Microsoft SQL Server as the data source
Note If your machine's SQL Server installation is not set up to allow the current Windows user to access the database using Windows Authentication, you will need to adjust these security settings according to your machine.
Figure 9. Adding a connection to the SQL Server Northwind database
The new data connection is displayed in the wizard, as shown in Figure 10.
Figure 10. The new Northwind SQL Server database connection
Figure 11. Changing the connection string name
Note If you are viewing the screen cast that corresponds to this tutorial, you might notice that the presenter selects a subset of columns; the presenter is using a Customers table that has been modified from the original schema. You can just select the Customers table.
Figure 12. Selecting the Customers table
Visual Studio adds the ServerNorthwindDataSet typed DataSet to your project. Now, you must add the Customers table to the application's form.
Figure 13. Adding the Customers table to Form1's Panel1 control (Click on the picture for a larger image)
Visual Studio adds the customersBindingNavigator and customersDataGridView controls to the form and several other controls to the form's component tray.
Notice that now the customersBindingNavigator control obscures the top part of the customersDataGridView control, as shown in Figure 14.
Figure 14. The customersBindingNavigator control obscures the top part of the customersDataGridView control.
In order to arrange the form's controls more easily, you will now use the Visual Studio Document Outline pane. You will be moving the customersBindingNavigator control, so that it is contained within the scope of the top panel of the splitter control. By moving the customersBindingNavigator control within the scope of the top panel of the splitter control, the customersBindingNavigator control and the customersDataGridView control dock within the same container and therefore properly share the display area, making the entire customersDataGridView control completely visible.
The Document Outline pane is displayed, as shown in Figure 15.
Figure 15. The Form1 Document Outline
Figure 16. Dropping customersBindingNavigator below customersDataGridView
You have just defined the customersBindingNavigator control to be contained within the scope of the splitContainer1.Panel1 control, and you have arranged the control's Z-orders so that they share the docking space in such a way that both controls are fully visible. The Document Outline should now appear like Figure 17.
Figure 17. The revised Document Outline
Form1 should now look like Figure 18, with both controls sharing the docking space and fully visible.
Figure 18. The modified Form1
Eventually, the bottom part of the form will display the contents of a local SQL Server Compact Edition copy of the Northwind Customers table. Later in this tutorial, you will change the data contained within the local SQL Server Compact Edition database and synchronize the local data with the SQL Server database. As you synchronize changes made to the local database with the server database, you will need a convenient way to reload the server data into the customersDataGridView that you have configured on the top part of the form; therefore, instead of just loading the server data into the application when the form is initially loaded, you will add a button and code to the form that will load the server data each time that you click the button.
Figure 19. The customersBindingNavigator control
Figure 20. The customersBindingNavigator Add ToolStripButton button's menu
The tool strip should now look like Figure 21.
Figure 21. The Load Server Data button has been added to the tool strip.
Now, you must add code to load the server data when the new button is clicked. Visual Studio has already generated this code for you, but you must move it from the form's Load event handler to the button's Click event handler.
The revised Form1 code should now look like the following code example.
private void Form1_Load(object sender, EventArgs e)
{
}
private void loadServerDataButton_Click(object sender, EventArgs e)
{
this.customersTableAdapter.Fill(this.serverNorthwindDataSet.Customers);
}
Now that you have created an application that loads SQL Server data and displays it, you are ready to add code to use RDA to retrieve a copy of the data from the server to a local SQL Server Compact Edition database. Instead of creating a local SQL Server Compact Edition database at design time, you will add code to check for the existence of a local database at run time when the user clicks a button to retrieve the data locally and, if it does not exist, you will create the local database at that time.
In the same way as in the previous task, you will now add another button to the tool strip.
The tool strip should now look like Figure 22.
Figure 22. The RDA Pull button has been added to the tool strip.
Now, you must add a Click event handler for the button to retrieve the data from the SQL Server Customers table and store it in a new table within a SQL Server Compact Edition database using RDA.
Cursor.Current = Cursors.WaitCursor;
try
{
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
Cursor.Current = Cursors.Default;
}
Just as you did in the case of the server database, you will store the local SQL Server Compact Edition database connection string as a setting in the Project Designer. In the server case, the connection string was automatically created by the Add Data Source wizard. In the case of the SQL Server Compact Edition database, you'll be creating the database programmatically instead of using the wizard to add the SQL Server Compact Edition data source; therefore, you must explicitly add the connection string to the project settings.
Figure 23. Adding a new connection string setting to the project (Click on the picture for a larger image)
Note If the Choose Data Source dialog box appears instead of the Add Connection dialog box, continue to the next step.
Note If the Choose Data Source dialog box appeared instead of the Add Connection dialog box, you must press the Continue button.
Figure 24. Choosing Microsoft SQL Server 2005 Compact Edition as the data source
Figure 25. Adding a connection to the local SQL Server Compact Edition Northwind database
Figure 26. A new connection string setting that points to the local SQL Server Compact Edition database (Click on the picture for a larger image)
When you pull data into a local database using RDA, the local database must already exist; therefore, you will now add a helper function to determine whether or not the database exists.
The code snippet that you are going to add uses the System.Data.SqlServerCe namespace, so that you must first add a reference to that namespace.
using System.Data.SqlServerCe;
To reduce the amount of code that you must type, you will use the code snippets that you installed in preparation for this tutorial.
Figure 27. The Insert Snippet menu
private bool verifyDatabaseExists()
{
bool createdDatabase = false;
using (SqlCeConnection conn = new SqlCeConnection())
{
conn.ConnectionString =
Properties.Settings.Default.LocalNorthwindConnectionString;
if (!System.IO.File.Exists(conn.Database))
{
createdDatabase = true;
using (SqlCeEngine engine = new
SqlCeEngine(Properties.Settings.Default.LocalNorthwindConnectionString))
engine.CreateDatabase();
}
}
return createdDatabase;
}
This code first declares a bool flag named createdDatabase to track whether or not the database has been created. The code then creates an instance of a SqlCeConnection object named conn and sets the conn's ConnectionString property to the value of the local SQL Server Compact Edition connection string project setting that you created previously. The project setting's value is accessed by referencing Properties.Settings.Default and the name of the setting that you created, LocalNorthwindConnectionString. When you associate the connection string with the SqlCeConnection instance, the Database property is assigned the actual database file path, because a SQL Server Compact Edition database is simply a file. Next, the code passes this database path to System.IO.File.Exists to determine if the database file exists. If it does not exist, createdDatabase is set to true, and an instance of SqlCeEngine named engine is created, passing the LocalNorthwindConnectionString setting value. Finally, engine's CreateDatabase method is called, creating an empty SQL Server Compact Edition database file, at the specified path, and the value of createdDatabase is returned. The CreateDatabase method contains all of the logic necessary to create the database file, so that you don't have to use any T-SQL.
try
{
verifyDatabaseExists();
}
In order to use RDA to pull a copy of data locally, you must create an instance of the base RDA class, SqlCeRemoteDataAccess, and initialize several of its properties. Because you will need this object both when pulling and pushing data, you will encapsulate its creation and initialization in a class-level method.
SqlCeRemoteDataAccess rda = getRDAObject();
Instead of requiring direct client access to SQL Server data, RDA enables access through a Microsoft IIS Web server, so that the data can be accessed remotely and securely over the Internet without requiring SQL Server to be directly available on the Internet. RDA uses an IIS server component that acts as the intermediary between the SQL Server Compact Edition client database and the SQL Server database. You must assign the URL of the IIS server that is configured as the intermediary to the SqlCeRemoteDataAccess.InternetUrl property.
Note Because the IIS server component is the actual client to the SQL Server database instead of your remote application, the interaction between the IIS server component and the SQL Server database is very efficient and even takes advantage of database connection pooling.
Note Having configured your computer for RDA according to this tutorial's prerequisite tutorial, "Configuring Internet Information Services for SQL Server 2005 Compact Edition Remote Data Access and Merge Replication," you should be able to verify that Web access to the RDA server component is functioning properly by using your browser to browse to http://localhost/Sync/sqlcesa30.dll and seeing the Web response Microsoft SQL Server Compact Edition Server Agent displayed in the browser.
private SqlCeRemoteDataAccess getRDAObject()
{
}
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess();
rda.InternetUrl = "http://localhost/Sync/sqlcesa30.dll";
rda.LocalConnectionString = Properties.Settings.Default.LocalNorthwindConnectionString;
return rda;
The completed getRDAObject function should now look like the following code example.
private SqlCeRemoteDataAccess getRDAObject()
{
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess();
rda.InternetUrl = "http://localhost/Sync/sqlcesa30.dll";
rda.LocalConnectionString =
Properties.Settings.Default.LocalNorthwindConnectionString;
return rda;
}
Note There are several other properties available to configure the rda object, such as Internet server logon information and proxy-server information.
rda.Pull("Contacts",
rda.Pull("Contacts",
"SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address,
City, Region, PostalCode, Country, Phone, Fax FROM Customers",
Note You could use the Visual Studio Query Designer to build this T-SQL statement. For a demonstration of this technique, see the screen cast that corresponds to this tutorial or the tutorial titled "SQL Server 2005 Compact Edition Data Access with the SqlCeResultSet and Visual C#.NET."
Because RDA was released when OLE DB providers were the standard for connecting to SQL Server, RDA requires an OLE DB connection string to the SQL Server as the oleDBConnectionString parameter. To generate a connection string easily, you can again use the Project Designer.
Figure 28. Selecting Microsoft SQL Server as the data source and .NET Framework Data Provider for OLE DB as the data provider
Because the queries that you submit to RDA are not being executed by your client-side logon, but are instead being executed on the Web server by the IIS process logon, you should not generate a connection string with Windows Authentication unless you have set up the IIS process to run as a user that has been configured to access the SQL Server. Instead of performing that configuration in this tutorial, you should just use the sa account or another SQL Server user that you have configured.
Note If your SQL Server was installed to use only Windows Authentication, you will need to set up your IIS process to run as your Windows user account and make sure that it has been configured to access the SQL Server.
Figure 29. Connecting to the SQL Server Northwind database using an OLE DB provider
rda.Pull("Contacts",
"SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address,
City, Region, PostalCode, Country, Phone, Fax FROM Customers",
Properties.Settings.Default.ServerOleDBNorthwindConnectionString,
The trackOption parameter lets you specify two attributes of the table that is created by the pull operation. The first attribute is whether or not local data changes will be tracked for potential pushing back to the server. The second attribute is whether the local table will be defined with the same indexes and primary key with which the server's table is defined.
rda.Pull("Contacts",
"SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address,
City, Region, PostalCode, Country, Phone, Fax FROM Customers",
Properties.Settings.Default.ServerOleDBNorthwindConnectionString,
RdaTrackOption.TrackingOnWithIndexes,
rda.Pull("Contacts",
"SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address,
City, Region, PostalCode, Country, Phone, Fax FROM Customers",
Properties.Settings.Default.ServerOleDBNorthwindConnectionString,
RdaTrackOption.TrackingOnWithIndexes,
"Contacts_Errors");
The rdaPullButton_Click event handler should now look like the following code example.
private void rdaPullButton_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
verifyDatabaseExists();
SqlCeRemoteDataAccess rda = getRDAObject();
rda.Pull("Contacts",
"SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address,
City, Region, PostalCode, Country, Phone, Fax FROM Customers",
Properties.Settings.Default.ServerOleDBNorthwindConnectionString,
RdaTrackOption.TrackingOnWithIndexes,
"Contacts_Errors");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
Cursor.Current = Cursors.Default;
}
}
The data is loaded from the SQL Server and displayed in the application, as shown in Figure 30.
Figure 30. Testing the application
In the next task, you will add the local SQL Server Compact Edition database file to your project and use this database to help generate the application's remaining user interface.
Note You might need to hover your mouse pointer over the buttons to see their names. The button is outlined in Figure 31.
Figure 31. The Northwind.sdf file created for the Debug build
Correctly assuming that you want to use this database as a data source in your application, Visual Studio displays the Data Source Configuration Wizard, as shown in Figure 32.
Figure 32. The Data Source Configuration Wizard
Note The details of working with RDA error tables are outside the scope of this tutorial, but you can learn more by reading " RDA Conflict Detection and Reporting," in the MSDN Library.
Figure 33. Choosing to include the Contacts table in the localNorthwindDataSet
Note You might need to click the Data Sources Refresh button to see the new data source.
Form1 should now look like Figure 34.
Figure 34. Form1 now contains grids for both server and client data.
The Document Outline should now look like Figure 35.
Figure 35. Form1 now contains controls for both server and client data.
Form1 should now look like Figure 36.
Figure 36. Form1 now contains controls for both server and client data.
The tool strip should now look like Figure 37.
Figure 37. The Load Client Data button has been added to the tool strip.
Now, you must add code to load the client data when the button is clicked. Visual Studio has already generated this code for you, but you must move it from the form's Load event handler to the button's Click event handler.
The revised loadClientDataButton_Click code should now look like the following code example.
private void loadClientDataButton_Click(object sender, EventArgs e)
{
this.contactsTableAdapter.Fill(this.localNorthwindDataSet.Contacts);
}
In order to save the local data, you need a Save button on the new tool strip. For simplicity, you will copy the Save button from the customersBindingNavigator control and paste it onto the bindingNavigator1 control. You will then add code to the new button that saves the local data to the SQL Server Compact Edition database.
The tool strip should now look like Figure 38.
Figure 38. The Save Client Data button has been added to the tool strip.
Saving your application's data is a three-step process: First, the data in the contactsDataGridView grid is applied to the contactsBindingSource binding source; next, the contactsBindingSource applies the data to the underlying Contacts DataTable in the localNorthwindDataSet typed DataSet; finally, the DataSet's data is saved to the database file.
this.Validate();
this.contactsBindingSource.EndEdit();
this.contactsTableAdapter.Update(this.localNorthwindDataSet.Contacts);
The finished saveClientDataButton_Click event handler should look like the following code example.
private void saveClientDataButton_Click(object sender, EventArgs e)
{
this.Validate();
this.contactsBindingSource.EndEdit();
this.contactsTableAdapter.Update(this.localNorthwindDataSet.Contacts);
}
Now, you must add a button to perform the RDA push.
The tool strip should now look like Figure 39.
Figure 39. The RDA Push button has been added to the tool strip.
Cursor.Current = Cursors.WaitCursor;
try
{
SqlCeRemoteDataAccess rda = getRDAObject();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
Cursor.Current = Cursors.Default;
}
SQL Server Compact Edition internally tracks the server table that was used to populate the local table during the pull action. It then uses that information to transmit the required INSERT, UPDATE, and DELETE statements to the server.
rda.Push("Contacts",
Properties.Settings.Default.ServerOleDBNorthwindConnectionString,
RdaBatchOption.BatchingOn);
The finished rdaPushButton_Click event handler should look like the following code example.
private void rdaPushButton_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
SqlCeRemoteDataAccess rda = getRDAObject();
rda.Push("Contacts", Properties.Settings.Default.ServerOleDBNorthwindConnectionString,
RdaBatchOption.BatchingOn);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
Cursor.Current = Cursors.Default;
}
}
Your application displays the error message that is shown in Figure 40.
Figure 40. The RDA pull action fails, because the Contacts table already exists.
Because the Contacts table already exists in the local SQL Server Compact Edition database, the RDA pull action fails. In order to protect existing data from being overwritten, RDA does not support populating an existing local table, so you must add code to deal with this situation.
Now, you will add a helper function to delete a table if it exists from the code snippets that you installed in preparation for this tutorial.
private bool deleteTable(string tableName)
{
bool tableFound = false;
using (SqlCeConnection conn = new SqlCeConnection())
{
SqlCeCommand cmd = new SqlCeCommand();
conn.ConnectionString =
Properties.Settings.Default.LocalNorthwindConnectionString;
cmd.Connection = conn;
cmd.CommandText = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_NAME = @tableName";
cmd.Parameters.Add("@tableName", tableName);
conn.Open();
if (cmd.ExecuteScalar().Equals(1))
{
tableFound = true;
cmd.Parameters.Clear();
cmd.CommandText = String.Format("DROP TABLE {0}", tableName);
cmd.ExecuteNonQuery();
}
}
return tableFound;
}
This function receives a string parameter, tableName, to indicate the name of the table to delete. The code starts by declaring a bool flag, tableFound, to track whether or not the table exists in the database. The code then creates a SqlCeConnection object, conn, and points it to the local SQL Server Compact Edition database with Properties.Settings.Default.LocalNorthwindConnectionString. A SqlCeCommand object, cmd, is used to execute a T-SQL statement that selects a count from the special SQL Server Compact Edition table INFORMATION_SCHEMA.TABLES, where the TABLE_NAME equals the value passed in to the tableName parameter. INFORMATION_SCHEMA.TABLES is a SQL Server Compact Edition system table that contains a row for each table currently in the database; therefore, if a row is found with the indicated table name, the cmd object is reused to issue a T-SQL DROP statement that deletes the table from the database. Finally, the bool tableFound value is returned.
deleteTable("Contacts");
The modified rdaPullButton_Click event handler should look like the following code example.
private void rdaPullButton_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
verifyDatabaseExists();
deleteTable("Contacts");
SqlCeRemoteDataAccess rda = getRDAObject();
rda.Pull("Contacts",
"SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address,
City, Region, PostalCode, Country, Phone, Fax FROM Customers",
Properties.Settings.Default.ServerOleDBNorthwindConnectionString,
RdaTrackOption.TrackingOnWithIndexes,
"Contacts_Errors");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
Cursor.Current = Cursors.Default;
}
}
Now, you are ready to test the application. In order to test the application as if this were the first that time you were running the application, you will first delete the local database copy in the Debug build folder.
Now, you will prevent the project's copy of Northwind.sdf from being copied to the location from which you just deleted it.
Note Because you have deleted the local database, and because there is no error-trapping logic around the Load Client Data handler, you should not click the Load Client Data button yet, or you will receive an unhandled error.
The application should now have all 91 rows loaded from each database, as shown in Figure 41.
Figure 41. The application has loaded both server and client data.
Your data change has now been saved to the server, but your local database copy still contains the old data. To get the updated data into your local copy of the SQL Server Compact Edition database, you have to perform the RDA pull operation again.
RDA is designed to receive a snapshot of server data on the client, track changes, and then push the changes back to the client; RDA does not support merging server data with existing changes to the local data. To retrieve server changes, you must delete the local table and then pull all of the data from the server again. Because of the RDA requirement that the local table not exist when performing the pull operation, all local data changes are lost when you perform the pull operation.
Figure 42. The application has loaded both server and client data. (Click on the picture for a larger image)
Figure 43. The application has pushed the local data back to the server. (Click on the picture for a larger image)
RDA is a solution that is designed specifically for SQL Server Compact Edition to communicate with SQL Server. Unlike other synchronization technologies, like merge replication, the SQL Server instance does not require any changes to the server data or database. As far as the SQL Server instance is concerned, the RDA client is just another database client that issues SELECT, INSERT, UPDATE, and DELETE commands. RDA's lightweight server impact often makes it an excellent replication choice.
RDA's lightweight design does, however, require that the system designer ensure that data is well partitioned, so that each client modifies a unique subset of the data. The client is able to pull down an initial data snapshot and the client is able to push locally made changes back to the server. These changes are applied without regard for conflicts with changes made on the server or by other clients. The client changes simply overwrite the server's current state. There is a similar issue with regard to downloading new or modified records from the server. When RDA pulls data down from the server, it simply issues a T-SQL statement. There is no implicit concept of getting only new or modified records. Individual systems must be specifically designed to manage these.
The application should now look like Figure 44.
Figure 44. Changes have been made to both the server and local data. (Click on the picture for a larger image)
Figure 45. The RDA push operation has overwritten the modified server data. (Click on the picture for a larger image)
In this tutorial, you performed the following exercise:
In this tutorial, you have learned how to create a Windows Forms application using Visual C#.NET that synchronizes data between a SQL Server 2005 database and a SQL Server 2005 Compact Edition database using SQL Server 2005 Compact Edition Remote Data Access (RDA). RDA is a simple two-tier, but scalable synchronization system. The client does not connect directly to the server database, but instead sends requests through a Web server, which has the benefit of making the contents of the SQL Server database available without exposing the SQL Server database directly to the Internet. The client does have knowledge of the server database information, such as data queries and the connection string. Merge replication is another available synchronization implementation that handles changes on both the server and client, including conflict resolution.
Before you begin this tutorial, you must be sure that the following procedures are completed.
To install Internet Information Services
To attach the Northwind sample database to SQL Server
After installing the setup files for this tutorial, you must attach the Northwind sample database to your SQL Server.
To install code snippets
This tutorial uses predefined Visual Studio code snippets to save time in typing some of the code that is necessary for the application. The code snippets are provided as part of this tutorial's installation, but you must add them to your Visual Studio environment according to the following steps.
To configure IIS for SQL Server Compact Edition synchronization
Before you begin this tutorial, you must configure your computer's IIS for SQL Server 2005 Compact Edition synchronization as described in the tutorial titled "Configuring Internet Information Services for SQL Server 2005 Compact Edition Remote Data Access and Merge Replication."