By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,120 Members | 1,786 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,120 IT Pros & Developers. It's quick & easy.

c# - Mobile - Connecting to DB

maxx233
P: 32
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 myConnectionString = "Integrated Security=false;" +
"Server=10.3.0.72;" +
"Initial Catalog=testDB;" +
"User Id=theUserName;" +
"Password=thePassword;" +
"connection timeout=30";
SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand(myQuery, myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
MessageBox.Show("Yup");
}
catch
{
MessageBox.Show("Nope");
}

}
Mar 31 '08 #1
Share this Question
Share on Google+
1 Reply


maxx233
P: 32
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\CompactFramework\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\v2.0

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

Maxx

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 myConnectionString = "Integrated Security=false;" +
"Server=10.3.0.72;" +
"Initial Catalog=testDB;" +
"User Id=theUserName;" +
"Password=thePassword;" +
"connection timeout=30";
SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand(myQuery, myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
MessageBox.Show("Yup");
}
catch
{
MessageBox.Show("Nope");
}

}
Mar 31 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.