c# - Mobile - Connecting to DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxx233
    New Member
    • Nov 2007
    • 32

    c# - Mobile - Connecting to DB

    Hello,
    I'm trying my first application for a mobile device. I'm doing it up for a pocket pc 2003 device, and all this app does is take a value that's in a textbox (a barcode string), and INSERT it into a test DB that has a single table and a single field just for this purpose. When I run it on the virtual pocket PC emulator it works fine, but when it's actually on the hardware device I've got, no go. The device is running off our wireless network, gets an IP, and can make a terminal services connection with the DB server. I can ping the device from my workstation. When I look at SQL profiler I don't see any attempted connections from the device however, but I do see connections from the emulator when I try from there. This is probably something really stupid bear in mind - this is my first *attempt* at a mobile app, and I don't normally work on pocket PC devices either. Any ideas?

    Here's my code (I know I *should* be doing SQL paramaters, I'll fix it after I get this working. This is just how I learned and am most comfortable with still, unfortunately):

    private void btnSubmit_Click (object sender, EventArgs e)
    {
    string myQuery = "INSERT INTO Devices (Barcode) VALUES ('" + this.txtBarcode .Text + "');";
    string myConnectionStr ing = "Integrated Security=false; " +
    "Server=10.3.0. 72;" +
    "Initial Catalog=testDB; " +
    "User Id=theUserName; " +
    "Password=thePa ssword;" +
    "connection timeout=30";
    SqlConnection myConnection = new SqlConnection(m yConnectionStri ng);
    SqlCommand myCommand = new SqlCommand(myQu ery, myConnection);
    try
    {
    myConnection.Op en();
    myCommand.Execu teNonQuery();
    MessageBox.Show ("Yup");
    }
    catch
    {
    MessageBox.Show ("Nope");
    }

    }
  • maxx233
    New Member
    • Nov 2007
    • 32

    #2
    OK, I solved my own problem. First I hard rebooted, which lost everything on the device. So I reinstalled .NET CF from a cab file located in C:\Program Files\Microsoft .NET\SDK\Compac tFramework\v2.0 \WindowsCE, which was different from my previous install (I believe.. it was pre-existing on the device when I got it)

    Then I added an exception to my catch block so I could see the error it was pulling up, and either as a result of that, or as a result of the different version of compact framework, I got something like: "can't find PInvoke DLL 'dbnetlib.dll'" , which a quick google search found this , which basically says to install the sqlclient from C:\Program Files\Microsoft Visual Studio 8\SmartDevices\ SDK\SQL Server\Client\v 2.0

    Did that and problem solved. Thanks to anyone who thought about it though!

    Maxx

    Originally posted by maxx233
    Hello,
    I'm trying my first application for a mobile device. I'm doing it up for a pocket pc 2003 device, and all this app does is take a value that's in a textbox (a barcode string), and INSERT it into a test DB that has a single table and a single field just for this purpose. When I run it on the virtual pocket PC emulator it works fine, but when it's actually on the hardware device I've got, no go. The device is running off our wireless network, gets an IP, and can make a terminal services connection with the DB server. I can ping the device from my workstation. When I look at SQL profiler I don't see any attempted connections from the device however, but I do see connections from the emulator when I try from there. This is probably something really stupid bear in mind - this is my first *attempt* at a mobile app, and I don't normally work on pocket PC devices either. Any ideas?

    Here's my code (I know I *should* be doing SQL paramaters, I'll fix it after I get this working. This is just how I learned and am most comfortable with still, unfortunately):

    private void btnSubmit_Click (object sender, EventArgs e)
    {
    string myQuery = "INSERT INTO Devices (Barcode) VALUES ('" + this.txtBarcode .Text + "');";
    string myConnectionStr ing = "Integrated Security=false; " +
    "Server=10.3.0. 72;" +
    "Initial Catalog=testDB; " +
    "User Id=theUserName; " +
    "Password=thePa ssword;" +
    "connection timeout=30";
    SqlConnection myConnection = new SqlConnection(m yConnectionStri ng);
    SqlCommand myCommand = new SqlCommand(myQu ery, myConnection);
    try
    {
    myConnection.Op en();
    myCommand.Execu teNonQuery();
    MessageBox.Show ("Yup");
    }
    catch
    {
    MessageBox.Show ("Nope");
    }

    }

    Comment

    Working...