469,366 Members | 2,243 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

how do I open a sql database connection for mobile device while running vb emulator?

2
I've been trying to open a connection to my sql database so i can add new rows and make edits to already existing rows. On the ~conn.Open();~ part i keep getting an expection thrown about the sqlinternalconnection... how do i fix this code or is there something i need to change in vb or the sql server settings themselves?

Expand|Select|Wrap|Line Numbers
  1. string pName = textBox6.Text.Trim();
  2.             string pMobile1 = textBox5.Text.Trim();
  3.             string pHome = textBox3.Text.Trim();
  4.             string pBusiness = textBox2.Text.Trim();
  5.             string pEmail = textBox1.Text.Trim();
  6.             string pCategory = comboBox1.SelectedText.Trim();
  7.  
  8.  
  9.             Debug.Write("test0 ");            
  10.             SqlConnection conn = new SqlConnection(
  11.                 "Server = CLB125_25; Data Source = \\C:Documents and Settings\\SLU Student\\Desktop\\SmartDeviceProject1\\database1.sdf");
  12.  
  13.             Debug.Write("test1 ");
  14.             SqlDataReader rdr = null;
  15.  
  16.             Debug.Write("test2 ");
  17.             try
  18.             {
  19.  
  20.                 conn.Open();
  21.                 Debug.Write("test3");
  22.  
  23.                 string actionString = "INSERT INTO Contacts(Name, Home_Phone, E-Mail, Address, Mobile, Category) VALUES(" + pName.ToString() + "," + pHome.ToString() + "," + pEmail.ToString() + "," + pBusiness.ToString() + "," + pMobile1.ToString() + "," + pCategory.ToString() + ")";
  24.  
  25.                 SqlCommand cmd = new SqlCommand(actionString, conn);
  26.  
  27.                 cmd.ExecuteNonQuery();
  28.  
  29.                 rdr = cmd.ExecuteReader();
  30.  
  31.                 while (rdr.Read())
  32.                 {
  33.                     Console.WriteLine(rdr[0]);
  34.                 }
  35.             }
  36.             catch (SqlException d)
  37.             {
  38.                 Console.Write(d);
  39.             }
  40.             finally
  41.             {
  42.  
  43.                 if (rdr != null)
  44.                 {
  45.                     rdr.Close();
  46.                 }
  47.  
  48.                 if (conn != null)
  49.                 {
  50.                     conn.Close();
  51.                 }
  52.             }
  53.  
Nov 5 '09 #1
3 2950
markmcgookin
648 Expert 512MB
At what stage does this exception occour?

Have you hear of a break point? if you hit F9 on a line of code the system will stop when it runs to that line, you can then step through your code using F10 and F11 line by line to see where the error occours.
Nov 9 '09 #2
markmcgookin
648 Expert 512MB
Your problem is that you seem to be trying to connect to an .sdf file on your desktop from the PDA... put the sdf on the emulator itself then connect to it...

i.e. "My Documents\Business\myDatabase.sdf"

If you want to share a folder to get the file on there go to the options for the emulator "File > Configure" I think.. then add a shared folder from your PC, this will show up as a memory card on the emulator allowing you to move/access files from the PC on the emulator
Nov 9 '09 #3
zakuro
2
This was exactly what i needed. I was able to finish my project with this.
Nov 18 '09 #4

Post your reply

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

Similar topics

2 posts views Thread by Schraalhans Keukenmeester | last post: by
3 posts views Thread by .:.:. igor_sb .:.:. | last post: by
1 post views Thread by =?Utf-8?B?V29vZGdub21l?= | last post: by
2 posts views Thread by rodmc | last post: by
9 posts views Thread by =?Utf-8?B?RGFuaWVs?= | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.