Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Nov 2009
Posts: 2
#1: 2 Weeks Ago
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.  
markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Posts: 546
#2: 2 Weeks Ago

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


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.
markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Posts: 546
#3: 2 Weeks Ago

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


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
Newbie
 
Join Date: Nov 2009
Posts: 2
#4: 6 Days Ago

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


This was exactly what i needed. I was able to finish my project with this.
Reply