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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zakuro
    New Member
    • Nov 2009
    • 2

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

    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 sqlinternalconn ection... how do i fix this code or is there something i need to change in vb or the sql server settings themselves?

    Code:
    string pName = textBox6.Text.Trim();
                string pMobile1 = textBox5.Text.Trim();
                string pHome = textBox3.Text.Trim();
                string pBusiness = textBox2.Text.Trim();
                string pEmail = textBox1.Text.Trim();
                string pCategory = comboBox1.SelectedText.Trim();
                
                
                Debug.Write("test0 ");            
                SqlConnection conn = new SqlConnection(
                    "Server = CLB125_25; Data Source = \\C:Documents and Settings\\SLU Student\\Desktop\\SmartDeviceProject1\\database1.sdf");
                
                Debug.Write("test1 ");
                SqlDataReader rdr = null;
                
                Debug.Write("test2 ");
                try
                {
                    
                    conn.Open();
                    Debug.Write("test3");
                    
                    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() + ")";
    
                    SqlCommand cmd = new SqlCommand(actionString, conn);
    
                    cmd.ExecuteNonQuery();
                    
                    rdr = cmd.ExecuteReader();
    
                    while (rdr.Read())
                    {
                        Console.WriteLine(rdr[0]);
                    }
                }
                catch (SqlException d)
                {
                    Console.Write(d);
                }
                finally
                {
                    
                    if (rdr != null)
                    {
                        rdr.Close();
                    }
    
                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    #2
    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.

    Comment

    • markmcgookin
      Recognized Expert Contributor
      • Dec 2006
      • 648

      #3
      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\Busin ess\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

      Comment

      • zakuro
        New Member
        • Nov 2009
        • 2

        #4
        thanks

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

        Comment

        Working...