Solved

SqlCeConnection String

Posted on 2004-08-16
13
970 Views
Last Modified: 2013-12-27
Hi, I'm trying to connect my pocket pc 2002 emulator(.NET Studio) to my database in SqlServer 2000. I was able to connect to the network my pc is on successfully but the problem is with the connection string. I don't know how to locate the server (which is my pc) and the database name coz the syntax of the connection string seems to be different than that of a normal sqlconnection. I think I need to fix the connection string. I tried the string in MSDN but it didnt work, I think the database name was local.

thanks,
ja7mad

0
Comment
Question by:ja7mad
13 Comments
 
LVL 10

Expert Comment

by:prakash_prk
ID: 11820174


You can't directly connect to SQL Server from your PDA
U first use Sql server CE and connect remotely to  SQl Server 2000

refer this link
http://www.ondotnet.com/pub/a/dotnet/2003/01/06/sqlce20.html

regards
Prakash
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 11823124
i would like to reccomend the Doings of a web service

HEres a fun and easy tutorial

http://www.west-wind.com/presentations/dotnetwebservices/DotNetWebServices.asp
0
 

Author Comment

by:ja7mad
ID: 11858040
I went through the tutorial u gave me guys, but i still seem to misunderstand the concept. I have a databse on SQL Server 2000 and I want to make an application on the pocket PC( im using C# + the pocket pc emulator 2002 the one that comes with .NET). I already have the databse on sql server , I was thinking of using Replication to synchronize the data. So I installed sql server CE on my pc but I dont think I'm doing it right. Can someone guide me or help me throught it ??

regards,
ja7mad
0
 
LVL 1

Expert Comment

by:skyknight
ID: 11959755
This is connection string for remote database
"Provider=sqloledb; Data Source=" + SqlServerName + ";Initial Catalog=" + RemoteDatabase + "; " "UID=" + RemoteDatabaseUserID + ";Password=" + RemoteDatabasePassword;

This is connection string for local database
"data source="\\My Documents\\demo.sdf"

for more information about replication, see this help, and find about replication:
http://download.microsoft.com/download/SQLServerCE/doc/2.0.4415.04/NT45XP/EN-US/sqlce.chm

Hope this can solve your problem
0
 

Author Comment

by:ja7mad
ID: 11994237
What I have achieved so far is:
-i can put the URL in the IE on the emulator and the link opens
-i made a button with the following code:

                                                SqlCeReplication repl = new SqlCeReplication(
                        @"http://pcrsahmadb/northwind/sscesa20.dll", //Internet URL to the CE agent
                        @"","", //Internet logon and pwd - blank for anonymous access
                        @"pcrsahmadb", //publsher
                        "UORDER","UORDER-5", //publ database and publication name
                        "replication", //name of this subscriber
                        @"Data Source=\My Documents\ReplDemo.sdf"); // CE connection string to local CE database
                  try
                  {
                        if (!File.Exists(@"\My Documents\ReplDemo.sdf"))
                        {
                              repl.AddSubscription(AddOption.CreateDatabase);
                        }
                        repl.Synchronize();
                  }
                  catch (SqlCeException ex)
                  {
                        for (int i=0; i < ex.Errors.Count; i++)
                        {
                              MessageBox.Show(ex.Errors[i].ToString());
                        }
                  }
                  finally
                  {
                        repl.Dispose();
                  }

but i still recieve the message : A request to send data to the computer running IIS has failed, see HRESUKT [,,,,,]"

please help
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ja7mad
ID: 11994247
Updating point value
0
 
LVL 1

Expert Comment

by:skyknight
ID: 11994521
did your iis server connect to lan?
Put your server in LAN. And try it again.
I hope it will work.
0
 

Author Comment

by:ja7mad
ID: 11994812
-What exactly do you mean by lan? My pc which is the IIS server in this situation is on a network.
I managed to overcome this error above by publishing the website in iis as an application that allows execs and scripts. the erorr is now gone but when i press the button after about 2 mins I receive: "sqlceserver.engine: sqlceserver " that 's all the error says.

-I now tried ran the application again  received the previous error :"A request to send data to the computer running IIS has failed, see HRESUKT [,,,,,]"

-could the problem be from the sql server 2000 coz after i have published the databse, i should push it to a subscriber right?? but when I want  to choose a new subscriber, I can only choose my pc and the databases on it. How can I choose the subscriber to be the pocket pc and the .sdf database on it??

what seems to be the problem?
0
 
LVL 1

Accepted Solution

by:
skyknight earned 100 total points
ID: 11995093
If you receive this text "sqlceserver.engine: sqlceserver" by exe this string "http://pcrsahmadb/northwind/sscesa20.dll", this mean your IIS is OK.
Your problem may be in your SQL SERVER  or IIS.

Have you try Remote Data Access? This is simplier than replication, if this work, replication can work too. It just a matter of code and setting in sql server.

ja7mad :  How can I choose the subscriber to be the pocket pc and the .sdf database on it??
(at your sql server)
1. you must create publisher

(at your ppc via coding)
2. create subcriber
3. synchronize it

this is my subscription module:


using System;
using System.Data.SqlServerCe;
using System.Text;
using System.Windows.Forms;


namespace replication
{
      /// <summary>
      /// Summary description for replication.
      /// </summary>
      public class replication
      {
            #region PROPERTY
            private string sInternetLogin;
            private string sInternetPassword;
            private string sInternetUrl;
            private string sLocalDatabase;

            private string sSqlServerName;
            private string sRemoteDatabase;
            private string sRemoteDatabaseUserID;
            private string sRemoteDatabasePassword;
            
            private string sPublisherName;
            private string sPublisherDatabase;
            private string sPublisherLogin;
            private string sPublisherPassword;
            private string sPublication;
            private string sSubscriberConnectionString;
            private string sSubscriber;
            #endregion

            #region FIELD
            public string InternetLogin
            {
                  set{sInternetLogin = value;}
                  get{return sInternetLogin;}
            }
            public string InternetPassword
            {
                  set{sInternetPassword = value;}
                  get{return sInternetPassword;}
            }
            public string InternetUrl
            {
                  set{sInternetUrl = value;}
                  get{return sInternetUrl;}
            }
            public string LocalDatabase
            {
                  set{sLocalDatabase = value;}
                  get{return sLocalDatabase;}
            }            
            public string LocalConnectionString
            {
                  get{return @"Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source="  + LocalDatabase;}
            }
                                    
            public string SqlServerName
            {
                  set{sSqlServerName = value;}
                  get{return sSqlServerName;}
            }
            public string RemoteDatabase
            {
                  set{sRemoteDatabase = value;}
                  get{return sRemoteDatabase;}
            }
            public string RemoteDatabaseUserID
            {
                  set{sRemoteDatabaseUserID = value;}
                  get{return sRemoteDatabaseUserID;}
            }            
            public string RemoteDatabasePassword
            {
                  set{sRemoteDatabasePassword = value;}
                  get{return sRemoteDatabasePassword;}
            }            

            public string RemoteConnectionString
            {
                  get
                  {
                        return "Provider=sqloledb; Data Source=" + SqlServerName + ";Initial Catalog=" + RemoteDatabase + "; " +
                              "UID=" + RemoteDatabaseUserID + ";Password=" + RemoteDatabasePassword;
                  }
            }            

            public string PublisherName
            {
                  set{sPublisherName = value;}
                  get{return sPublisherName;}
            }
                        
            public string PublisherDatabase
            {
                  set{sPublisherDatabase = value;}
                  get{return sPublisherDatabase;}
            }
            
            public string PublisherLogin
            {
                  set{sPublisherLogin = value;}
                  get{return sPublisherLogin;}
            }      
            
            public string PublisherPassword
            {
                  set{sPublisherPassword = value;}
                  get{return sPublisherPassword;}
            }      
            
            public string Publication
            {
                  set{sPublication = value;}
                  get{return sPublication;}
            }
            
            public string SubscriberConnectionString
            {
                  get{return LocalConnectionString;}
            }
                  
            public string Subscriber
            {
                  set{sSubscriber = value;}
                  get{return sSubscriber;}
            }                  
            #endregion

            public replication()
            {
                  //
                  // TODO: Add constructor logic here
                  //
                  InternetLogin                                    = "";
                  InternetPassword                        = "";
                  InternetUrl                                          = "http://kurniawan/ssce/sscesa20.dll";
                  LocalDatabase                              = "/My Documents/demo.sdf";

                  SqlServerName                              = "appservices";
                  RemoteDatabase                        = "demo";
                  RemoteDatabaseUserID            = "sa";
                  RemoteDatabasePassword      = "";

                  PublisherName                              = "MyPublisherName";
                  PublisherDatabase                        = "MyPublisherDatabase";
                  PublisherLogin                              = "MyPublisherLogin";
                  PublisherPassword                        = "MyPublisherPassword";
                  Publication                                          = "MyPublication";
                  Subscriber                                     = "MySubscriber";
            }


            public replication(string pInternetLogin,
                              string pInternetPassword,
                              string pInternetUrl,
                              string pLocalDataBase,
                              string pSqlServerName,
                              string pRemoteDatabase,
                              string pRemoteDatabaseUserID,
                              string pRemoteDatabasePassword,
                              string pPublisherName,
                              string pPublisherDatabase,
                              string pPublisherLogin,
                              string pPublisherPassword,
                              string pPublication,
                              string pSubscriber)
            {
                  //
                  // TODO: Add constructor logic here
                  //
                  InternetLogin                                    = pInternetLogin;
                  InternetPassword                        = pInternetPassword;
                  InternetUrl                                          = pInternetUrl;
                  LocalDatabase                              = pLocalDataBase;

                  SqlServerName                              = pSqlServerName;
                  RemoteDatabase                        = pRemoteDatabase;
                  RemoteDatabaseUserID            = pRemoteDatabaseUserID;
                  RemoteDatabasePassword      = pRemoteDatabasePassword;
                  
                  PublisherName                              = pPublisherName;
                  PublisherDatabase                        = pPublisherDatabase;
                  PublisherLogin                              = pPublisherLogin;
                  PublisherPassword                        = pPublisherPassword;
                  Publication                                          = pPublication;
                  Subscriber                                     = pSubscriber;
            }


            public void CreatingSubscription()
            {
                  SqlCeReplication repl = null;

                  try {
                         // Set the Replication object.
                        repl = new SqlCeReplication();
                        repl.InternetUrl       = InternetUrl;
                        repl.InternetLogin     = InternetLogin;
                        repl.InternetPassword  = InternetPassword;
                        repl.Publisher         = PublisherName;
                        repl.PublisherDatabase = PublisherDatabase;
                        repl.PublisherLogin    = PublisherLogin;
                        repl.PublisherPassword = PublisherPassword;
                        repl.Publication       = Publication;
                        repl.SubscriberConnectionString = SubscriberConnectionString;
                        repl.Subscriber        = Subscriber;

                              // Create the Local SSCE Database subscription.
                              repl.AddSubscription(AddOption.CreateDatabase);

                              // Synchronize to the instance of SQL Server 2000 to populate the Subscription.
                              repl.Synchronize();
                  }
   
                  catch(SqlCeException e) {
                        // Use your own error handling routine to show error information.
                        ShowErrors(e);
                  }

                  finally {
                        // Dispose of the Replication object.
                        repl.Dispose();
                  }
            }


            public void SynchronizeSubscription()
            {
                  SqlCeReplication repl = null;

                  try
                  {
                        // Set the Replication object.
                        repl = new SqlCeReplication();
                        repl.InternetUrl       = InternetUrl;
                        repl.InternetLogin     = InternetLogin;
                        repl.InternetPassword  = InternetPassword;
                        repl.Publisher         = PublisherName;
                        repl.PublisherDatabase = PublisherDatabase;
                        repl.PublisherLogin    = PublisherLogin;
                        repl.PublisherPassword = PublisherPassword;
                        repl.Publication       = Publication;
                        repl.SubscriberConnectionString = SubscriberConnectionString;
                        repl.Subscriber        = Subscriber;

                        // Synchronize to the instance of SQL Server 2000 to populate the Subscription.
                        repl.Synchronize();
                  }
                  catch(SqlCeException e)
                  {
                        // Use your own error handling routine to show error information.
                        ShowErrors(e);
                  }
                  finally
                  {
                        // Dispose of the Replication object.
                        repl.Dispose();
                  }
            }


            public void ReinitializeSubscription()
            {
                  SqlCeReplication repl = null;

                  try
                  {
                        // Set the Replication object.
                        repl = new SqlCeReplication();
                        repl.InternetUrl       = InternetUrl;
                        repl.InternetLogin     = InternetLogin;
                        repl.InternetPassword  = InternetPassword;
                        repl.Publisher         = PublisherName;
                        repl.PublisherDatabase = PublisherDatabase;
                        repl.PublisherLogin    = PublisherLogin;
                        repl.PublisherPassword = PublisherPassword;
                        repl.Publication       = Publication;
                        repl.SubscriberConnectionString = SubscriberConnectionString;
                        repl.Subscriber        = Subscriber;

                        // Mark the subscription for reinitialization with Upload first.
                        repl.ReinitializeSubscription(true);

                        // Synchronize to the instance of SQL Server 2000 to populate the Subscription.
                        repl.Synchronize();
                  }
                  catch(SqlCeException e)
                  {
                        // Use your own error handling routine to show error information.
                        ShowErrors(e);
                  }
                  finally
                  {
                        // Dispose of the Replication object.
                        repl.Dispose();
                  }
            }


            public void DropSubscription()
            {
                  SqlCeReplication repl = null;

                  try
                  {
                        // Set the Replication object.
                        repl = new SqlCeReplication();
                        repl.SubscriberConnectionString = SubscriberConnectionString;

                        // Drop the subscription and delete the database.
                        repl.DropSubscription(DropOption.DropDatabase);
                  }
                  catch(SqlCeException e)
                  {
                        // Use your own error handling routine to show error information.
                        ShowErrors(e);
                  }
                  finally
                  {
                        // Dispose of the Replication object.
                        repl.Dispose();
                  }

            }


            private static void ShowErrors(SqlCeException e)
            {
                  SqlCeErrorCollection errorCollection = e.Errors;

                  StringBuilder bld = new StringBuilder();
                  Exception inner = e.InnerException;

                  if (null != inner)
                  {
                        MessageBox.Show("Inner Exception: " + inner.ToString());
                  }
                  // Enumerate the errors to a message box.
                  foreach (SqlCeError err in errorCollection)
                  {
                        bld.Append("\n Error Code: " + err.HResult.ToString("X"));
                        bld.Append("\n Message   : " + err.Message);
                        bld.Append("\n Minor Err.: " + err.NativeError);
                        bld.Append("\n Source    : " + err.Source);

                        // Enumerate each numeric parameter for the error.
                        foreach (int numPar in err.NumericErrorParameters)
                        {
                              if (0 != numPar) bld.Append("\n Num. Par. : " + numPar);
                        }

                        // Enumerate each string parameter for the error.
                        foreach (string errPar in err.ErrorParameters)
                        {
                              if (String.Empty != errPar) bld.Append("\n Err. Par. : " + errPar);
                        }

                        MessageBox.Show(bld.ToString());
                        bld.Remove(0, bld.Length);
                  }
            }
      }
}


0
 

Author Comment

by:ja7mad
ID: 12003802
thanks for the code skyknight, I just want to ask u a  question:

-in the replication constructor, what does (Subscriber,publisher) stand for and from where can i check the PublisherLogin and password?

0
 
LVL 1

Expert Comment

by:skyknight
ID: 12003935
publisher = sql server publisher
subscriber = client that request data

you can get publisher login and password from your database user.
for more information  about replication, you should read sql replication.
Replication is not easy. But it's powerfull

 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I think the most popular question in our Windows Mobile Programming zone is about the backlight - we all want to keep it on when our application is running. Few years ago the function SystemIdleTimerReset() did this job. On our side we had to detec…
When I was a beginner in Windows Mobile programming, even for small test I used to create a single MFC dialog-based application with one button, and put my test code in the OnLButtonDown method. For Pocket PC it worked fine, on some Windows CE d…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now