PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 20, 2022

[FIXED] How do I connect to SDF on a Mobile device from desktop application?

 April 20, 2022     activesync, connection, desktop-application, sdf     No comments   

Issue

C# WinForms .Net 3.5 to SQL CE 3.5 on Mobile 6.1 Device

I'd like to make a connection from a desktop application to a SDF database on my Windows Mobile device while it's connected via ActiveSync. Visual Studio lets me create a Data Connection to my device. The connections tests OK and I can view the data in the database using Visual Studio.

I then create a form and try to fill a DataGridView. When I run the program I get an error that the path to the data base is not valid.

How am I supposed to specify the Mobile device path in the connection string?

In my App.Config, I've tried variations on the path, but none of them work:

connectionString="Data Source=Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf"

connectionString="Data Source=\Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf"

connectionString="Data Source=Program Files\SqlCeViaActiveSync\Orders.sdf"

connectionString="Data Source=\Program Files\SqlCeViaActiveSync\Orders.sdf"

The full connection string section looks like this:

<connectionStrings>
    <add name="SqlCeViaActiveSync.Properties.Settings.OrdersConnectionString"
        connectionString="Data Source=Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf"
        providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>

Also, I did make a reference to Microsoft.SqlServerCe.Client, as I found a few articles that mentioned it was necessary.

Can anyone point me to some recent articles/samples or let me know what I'm doing wrong?

Thanks!


Solution

I just found that the following works:

SqlCeConnection conn = new SqlCeConnection(@"Data Source='Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf';");
        conn.Open();
        using (SqlCeTransaction trans = conn.BeginTransaction())
        {
            using (SqlCeCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = "SELECT [OrderNumber] FROM [Orders];";
                trans.Commit();
                SqlCeDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    this.listBox1.Items.Add((string)dr["OrderNumber"]);
                }

                MessageBox.Show(dr.RecordsAffected.ToString());
            }
        }
        conn.Close();

It wasn't exactly what I was looking for but will work for this application.



Answered By - Elton Saunders
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing