Showing posts with label codeprivate. Show all posts
Showing posts with label codeprivate. Show all posts

Tuesday, March 20, 2012

problem on running replication on pocket pc

hi i tried to view a replication on a pocket pc app that i created. and i used the following code

private void Sync()
{
public string AppPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
SqlCeReplication repl = new SqlCeReplication();

repl.InternetUrl = @."http://naomi/sqlmobile/sqlcesa30.dll";
repl.Publisher = @."Naomi";
repl.PublisherDatabase = @."SQLMobile";
repl.PublisherSecurityMode = SecurityType.DBAuthentication;
repl.PublisherLogin = @."sa";
repl.PublisherPassword = @."<...>";
repl.Publication = @."SQLMobile";
repl.Subscriber = @."SQLMobile";
repl.SubscriberConnectionString = @."Data Source=""" + AppPath + @."\SqlMobile.sdf"";Max Database Size=128;Default Lock Escalation =100;";
try
{
repl.AddSubscription(AddOption.ExistingDatabase);
repl.Synchronize();
}
catch (SqlCeException e)
{
MessageBox.Show(e.ToString());
}

when i run it i keep on getting the error:
The SQL Mobile Subscription already exists. Publisher, PublisherDatabase, and Publication for this subscription should be different from any existing subscription.

However, i can still view the contents of the datagrid that refers to the database subscription.

1. What should i do in order to stop getting the error above?
2. If i edit the contents of the datagrid in the pocket pc app how will i update the replication in the sql server? thanks

With the line of code "repl.AddSubscription(AddOption.ExistingDatabase)" you are effectively trying to add a new subscription to your local SQL Mobile database every time your synchronize. You only need to perform the AddSubscription the first time you synchronize with the server.

What I typically do is use AddOption.CreateDatabase, which dynamically creates the SQL Mobile database (if it does not already exist) the first time synchronization occurs.

-Darren

Problem of vale setting

I have this .NET (VB) code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim myConnection As New SqlConnection(ConnectionString)
myConnection.Open()

Dim CommandText As String = "SELECT firstName FROM students Where Students.ID='" & IDinput & "' "

Dim myCommand As New SqlCommand(CommandText, myConnection)

'****this the problem, somthing is mising here******
Dim name As String = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

end sub

The SQL qurey return only one record each time (only one student name with specific ID number)

I want that variable "name" will get the value of the "firstName" filed.

How to do it??Use ExecuteScalar instead of ExecuteReader. ExecuteScalar is designed for situations like this where you want the query to return a single value.