Click here to Skip to main content
15,881,852 members
Articles / Mobile Apps

Pocket PC with SQL CE

Rate me:
Please Sign up or sign in to vote.
2.76/5 (26 votes)
29 Jan 2004CPOL2 min read 246.7K   583   45   74
This article demonstrates how to use SQL CE and SQL Server 2000 with the help of Remote Data Access (RDA)

Introduction

This article describes how to use SQL CE using VB. NET and how to transfer data from SQLCE (Pocket PC) to SQL Server 2000 which is running in your desktop system.

Client Requirement

  1. Pocket PC with Microsoft Windows powered
  2. Microsoft .Net compact Framework 1.0 (Default in PocketPC)

Server Requirement

  1. MS SQL server 2000 with SP3
  2. MS SQL CE 2000 with SP3
  3. Create DataBase named D1Temp and execute script "D1temp SQLScript.sql"

Background

The basic idea behind this work is to update any information on the fly. i.e. If I am traveling from one location to another location if I seen
or knowing some interesting information. If I want those information to my data storage then just need a pocket PC and Internet connection.

On the flight I can note all the information and transfer the same to my desktop, which is running in some part of the world. I won't worry about the memory size of my Pocket PC because all the information is posted to the remote database.

You can make this work as a template and do your own mobile device application.

Using the code

Download the source code in that you can find a SQL script named SQLSCRIPT.sql. Create a Database (I used D1Temp) and run the script. Open Config.xml and specify correctly

  • DatabaseServer
  • DatabaseName
  • DatabaseLogin
  • DatabasePassword
  • SQLCEURL
  • IISLogin
  • IISPassword
If you are not properly configure this XML file then you will not get the expected result. Note: Make sure you are properly configured your SQLCE virtual folder and the IIS. The Database.vb files holds all the database related connections and query handling. The below code is used to connect to the Host database and populate the data to SQL CE
VB.NET
'Connect to SQL 2000
Dim rdaOleDbConnectString As String = _
  "Provider=sqloledb; Data Source=" & _
  oDBConfig.DatabaseServer & ";Initial" & _
  " Catalog=" & oDBConfig.PublisherDB & ";User Id=" & _
  oDBConfig.PublisherLogin & ";Password=" & _
  oDBConfig.PublisherPassword

  'create an RDA object to connect to the SQL Server CE 
  'database on the mobile device: 
  'Initialize the RDA object.
  Try
    rda = New SqlCeRemoteDataAccess

    rda.InternetUrl = oDBConfig.SqlCeUrl
    rda.LocalConnectionString = _
    "Provider=Microsoft.SQLSERVER." & _
    "OLEDB.CE.2.0;Data Source=" & oDBConfig.LocalDBLocation & _
    oDBConfig.LocalDBName

    rda.InternetLogin = oDBConfig.IISLogin
    rda.InternetPassword = oDBConfig.IISPassword

    'Pull from SQL 2000
    rda.Pull("MyFavourite", "Select * from MyFavourite", _
    rdaOleDbConnectString, _
    RdaTrackOption.TrackingOnWithIndexes)
    .....        

Getting back the details from PDA to SQL 2000 also same as above code except rda.Pull. Here we have to use rda.push :-

VB.NET
rda.Push("MyFavourite", rdaOleDbConnectString, _
RdaBatchOption.BatchingOn)
And also I added some of functions for getting data into DataReader and executing SQL statements.

Points of Interest

When I tried using the emulator most of time it shows error "80072EFD request send data to the computer running IIS has failed for more information see HRESULT" even everything is configured properly. If I use my pocket PC instead of Emulator it works good. After that I used to run the SQL CE virtual folder path "http://sys1/sqlce/sscesa20.dll" often through my IE . Some times it works but most of time it does not. If this trick fails then I used this logic i.e. I will change IISLogin from "everest/rasheed" to "everest\rasheed" (Just changed the slash) if it fails next time then I will change IISLogin from "everest\rasheed" to "everest/rasheed" You won't believe it but this worked perfectly. I didn't know the secret of "slash" ;-)

History

  • First release 1.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
Called as Rasheed. Completed Master of Computer science. Working as Senior Consultant in Chennai, India.

Try to achive in different stream

Comments and Discussions

 
GeneralMy vote of 2 Pin
Rob Graham5-May-09 5:01
Rob Graham5-May-09 5:01 
Generaldb connection error Pin
ashuangrish27-Nov-08 21:44
ashuangrish27-Nov-08 21:44 
GeneralRe: db connection error Pin
rasheed197930-Nov-08 18:38
rasheed197930-Nov-08 18:38 
GeneralRe: db connection error Pin
ashuangrish1-Dec-08 0:53
ashuangrish1-Dec-08 0:53 
GeneralRe: db connection error Pin
ashuangrish5-Dec-08 0:28
ashuangrish5-Dec-08 0:28 
GeneralRe: db connection error Pin
omid200223-Feb-09 8:05
omid200223-Feb-09 8:05 
Generalhelp Rasheed :( Pin
three.leaf12-Sep-08 12:46
three.leaf12-Sep-08 12:46 
Generalphone incoming call information Pin
prats115-Jun-07 0:28
prats115-Jun-07 0:28 
GeneralE r r o r Pin
PavanPareta2-Jun-07 0:13
PavanPareta2-Jun-07 0:13 
Generalmissing method exception Pin
mokhabarat3-May-07 12:21
mokhabarat3-May-07 12:21 
Generalsql express Pin
rajeshatsrin20-Apr-07 5:01
rajeshatsrin20-Apr-07 5:01 
QuestionError when synchronize data from Pocket PC to Pc and opposite Pin
tommyitvn5-Dec-06 19:21
tommyitvn5-Dec-06 19:21 
Dear Rasheed,
I have a problem with synchonize data from Pocket PC to PC and opposite. It raise error

Message="A request to send data to the computer running IIS has failed. For more information, see HRESULT."
HResult=-2147012867
NativeError=28037


Now I use SQL Server Mobile 2005 and SQL Server Express 2005
I test SQL Server Mobile Agent, it runs well in PC:

http://192.168.2.12/SQLServerMobile/sqlcesa30.dll

I use Emulator in VS2005(not actual Pocket PC). I start IE in my Emulator with http://192.168.2.12/SQLServerMobile/sqlcesa30.dll
but It can not run. It message "Cannot connect for an unknow reason". To check your connection setting and change them if needed, tap Settings ..."

I can not execute Pull, also Push method!
This is source code:
-------------------------------------------------------------
SqlCeConnection cn = null;
string rdaOleDbConnectString = "Provider=sqloledb; Data Source=VANTINH\\SQLEXPRESS;" +
"Initial Catalog=" + "QLSV; " +
"User Id=" +
";Password=";
SqlCeRemoteDataAccess rda = null;
try
{
rda = new SqlCeRemoteDataAccess();
rda.InternetLogin = "username";
rda.InternetPassword = "password";
rda.InternetUrl = "http://192.168.2.12/SQLServerMobile/sqlcesa30.dll";
rda.LocalConnectionString = "Data Source=\\Program Files\\" + "Test.sdf";
if (this.chkDropTable.Checked)
{
cn = new SqlCeConnection(rda.LocalConnectionString);
cn.Open();
SqlCeCommand cmd = cn.CreateCommand();
cmd.CommandText = "DROP TABLE " + "HocSinh";
cmd.ExecuteNonQuery();
if (cn.State != ConnectionState.Closed)
cn.Close();
}
if (this.cmbTrackOption.Text == "TrackingOff")
rda.Pull("HocSinh",
"select * from HocSinh",
rdaOleDbConnectString,
RdaTrackOption.TrackingOff,
"ErrorTable");
if (this.cmbTrackOption.Text == "TrackingOn")
rda.Pull("HocSinh",
"select * from HocSinh",
rdaOleDbConnectString,
RdaTrackOption.TrackingOn,
"ErrorTable");
if (this.cmbTrackOption.Text == "TrackingOffWithIndexes")
rda.Pull("HocSinh",
"select * from HocSinh",
rdaOleDbConnectString,
RdaTrackOption.TrackingOffWithIndexes,
"ErrorTable");

if (this.cmbTrackOption.Text == "TrackingOnWithIndexes")
rda.Pull("HocSinh",
"select * from HocSinh",
rdaOleDbConnectString,
RdaTrackOption.TrackingOnWithIndexes,
"ErrorTable");
}
catch (SqlCeException exc)
{
MessageBox.Show(exc.Message);
return;
}
finally
{
//MessageBox.Show("Table is Pulled Successfully");
rda.Dispose();
this.Close();
}
-----------------------------------------------------------------------------------
Please help me to solve this problem!
-------------------------------------------------------------

Could you help me to solve this problem?
Thanks a lot!



Tommyitvn
AnswerRe: Error when synchronize data from Pocket PC to Pc and opposite Pin
rasheed197922-Dec-06 1:20
rasheed197922-Dec-06 1:20 
GeneralMissing Method Exception Pin
victorarce7-Jul-06 6:56
victorarce7-Jul-06 6:56 
GeneralRe: Missing Method Exception Pin
storystar31-Oct-06 8:57
storystar31-Oct-06 8:57 
Generalrasheed..plz help Pin
sudhacnaidu8-Jun-06 18:47
sudhacnaidu8-Jun-06 18:47 
GeneralRe: rasheed..plz help Pin
sudhacnaidu9-Jun-06 0:21
sudhacnaidu9-Jun-06 0:21 
GeneralRe: rasheed..plz help Pin
rasheed197911-Jun-06 16:55
rasheed197911-Jun-06 16:55 
Generalerror with initialize SQL Pin
sudhacnaidu8-Jun-06 18:41
sudhacnaidu8-Jun-06 18:41 
GeneralBook Pin
Baskras1214-May-06 2:58
Baskras1214-May-06 2:58 
GeneralRe: Book Pin
acc12345678907-Mar-07 2:51
acc12345678907-Mar-07 2:51 
GeneralNot able to Sync Pin
Arathi Vasupal26-Mar-06 23:45
Arathi Vasupal26-Mar-06 23:45 
GeneralIs there away to send to Desktop Ms Access Pin
silkkeng7-Mar-06 16:19
silkkeng7-Mar-06 16:19 
GeneralRe: Is there away to send to Desktop Ms Access Pin
rasheed197913-Mar-06 15:05
rasheed197913-Mar-06 15:05 
GeneralProblem installing SQL server CE Pin
TheFrnd1-Jan-06 17:45
TheFrnd1-Jan-06 17:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.