2
votes

I am trying to write a simple application that runs on a Windows Mobile 6 device and can connect to a SQL 2005 server and read and write to the database. It is ok if it only connects to the SQL server while it is docked.

I have never worked with mobile devices, so I may be thinking about it incorrectly. I created a DataSet and a TableAdapter like I would with a regular desktop app, but when I run the application in the emulator, I get a SqlException when I try to open the connection on the TableAdapter.

Is there something obvious I'm missing? Do I need to explicitly tell the emulator to act like it is docked? Does it need to be configured to see that it is in the network? I can ping the SQL server in question from within the app so there should be some connectivity

2
What do you mean by "ping the Sql Server"? Your most basic connection test ought to be the ability to browse to any web site from your emulator. Start there. P.S. Emulator network connections for windows mobile do tend to be squirrelly. i've had much better dock debugging real devices docked via USB. - Paul Sasik

2 Answers

2
votes

Here's a good link for setting up your emulator to connect to a network:

http://www.xdevsoftware.com/blog/post/Enable-Network-Connection-Windows-Mobile-6-Emulator.aspx

psasik is being polite when he describes emulator network connections as "squirrelly". I've never gotten them to work successfully, but this is because I always have an actual physical device handy, which I always go back to at the first hint of emulator problems.

2
votes

Thanks for the link! It was helpful, and I can confirm that I can connect to the network. Unfortunately, it still will not connect to the SQL server. I have distilled the code down to:

`

        string connStr;
        System.Data.SqlClient.SqlConnection myConn;

        try
        {
            connStr = @"Server='<server name/IP>';Database=<database name>; User Id=sa; Password=<password>";
            myConn = new System.Data.SqlClient.SqlConnection(connStr);
            myConn.Open();
        }
        catch (System.Data.SqlClient.SqlException se)
        {
            MessageBox.Show(se.ToString());
        }

`

This code throws an SQLException at the myConn.Open() with errorClass 20, number 17. The message is "SQL Server does not exist or access denied." The exact same code (copy/pasted) works perfectly in a winforms application. Am I doing everything correctly? Is it likely that the code is correct but that the emulator is causing my problems? Would it be worth asking the boss for a mobile device to try it on?