Click here to Skip to main content
15,847,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So we have an in-house program written in C# running on a Socket Mobile Pocket PC (SoMo650) with Windows Mobile 5. In the past few weeks the device has been VERY spotty in connecting to our SQL server database. Most mornings it works fine, but around 10:00 am (give or take half an hour) it just stops connecting completely; only working afterward on the bluest of moons. The program works fine on other computers 24/7, it's only the PPC and PPC emulators that are having problems. The next morning it starts working fine until ~10:00 am again. Here is the stack trace I get (I typed it out by hand, so sorry for any typos) :


at System.Data.SqlClient.SqlConnection.OnError()
at System.Data.SqlClient.SqlInternalConnection.OnError()
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.Tdsparser.Connect()
at System.Data.SqlClient.SqlInternalConnection.OpenAndLogin()
at System.Data.SqlClient.SqlInternalConnection..ctor()
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen()
at System.Data.Common.DbDataAdapter.FillInternal()
at System.Data.Common.DbDataAdapter.Fill()
at System.Data.Common.DbDataAdapter.Fill()
at ProgramZ.ProgramZTableAdapters.qryWarehousesTableAdapter.GetWarehouse()
at ProgramZ.frmCollection.frmCollection_Load()
at System.Windows.Forms.Form.OnLoad()
at System.Windows.Forms.Form._SetVisibleNotify()
at System.Windows.Forms.Form.set_Visible()
at System.Windows.Forms.Application.Run()
at ProgramZ.Program.Main()

When debugging in Visual Studio, the error message is "SqlException was unhandled". That's it. When I click on details, I get the following info:

[System.Data.SqlCLient.SqlException]  {"SqlException"}
Class                                 20
Errors                                {System.Data.SqlClient.SqlErrorCollection}
InnerException                        null
LineNumber                            0
Message                               "SqlException"
Number                                6
Procedure                             "ConnectionOpen(Connect())."
Server                                "ServerName"
Source                                ".Net SqlClient Data Provider"
StackTrace                            "at System.Data.SqlClient.SqlConnection.OnError()"...
State                                 0

The program is set up with a typical ADO connection. What the code is trying to do is populate a combobox with stuff from the server via a dataset; here is the code for that (located in form_load).

    //Get Warehouses and Locations for Comboboxes
    qryWarehousesBLL wHse = new qryWarehousesBLL();
    this.cboWarehouse.DataSource = wHse.GetqryWarehouses();
    this.cboWarehouse.DisplayMember = "MWH_WhsName";
    this.cboWarehouse.ValueMember = "MWH_WhsName";
    this.cboWarehouse.SelectedIndex = -1;
catch (Exception ex)
    System.Windows.Forms.MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
    MessageBoxIcon.Exclamation,     MessageBoxDefaultButton.Button1);

This program was written by someone else, but I think “qryWarehousesBLL” is referring to a small class, and here is the code that I found in that class:

private qryWarehousesTableAdapter _qryWarehousesAdapter = null;

protected qryWarehousesTableAdapter Adapter
                if (_qryWarehousesAdapter == null) _qryWarehousesAdapter = new qryWarehousesTableAdapter();
                return _qryWarehousesAdapter;

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
public ProgramZ.ProgramZ.qryWarehousesDataTable GetqryWarehouses()
                return Adapter.GetWarehouse();

Where the actual code is failing is when loading up the Visual Studio-created dataset (here is the code snippet where things go wrong).

[global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Select, true)]
public virtual ProgramZ.qryWarehousesDataTable GetWarehouse() 
    this.Adapter.SelectCommand = this.CommandCollection[0];
    ProgramZ.qryWarehousesDataTable dataTable = new ProgramZ.qryWarehousesDataTable();
    this.Adapter.Fill(dataTable); // <-- this is where the error is thrown
    return dataTable;

Any ideas what's going on? The fact that it works in the mornings for a few hours then just stops working completely is confusing me big time. This program has been working for years until recently. The package sql.ppc.wce5.armv4i is installed on the device (that package is needed for it to connect to SQL). We've tried restarting the server, reinstalling the software, a factory reset on the PPC and reinstalling everything. I've even went as far as try to rewrite the program from scrath and still no luck. Here's some more info on the device itself:

Manufacture: Socket Mobile, Inc
Product ID: SoMo650
Windows Mobile 5.0 with the Messaging and Security Feature Pack
OS 5.1.478 (Build 15706.3.5.2

Considering that the problem also happens with the PPC emulator in Visual Studio 2008, I doubt that info will help with anything. But there it is just in case. The device is connected via WiFi to our SqlServer 2000. There are about 5 more databases running on the server, about 3 of which are being used on a regular basis (as in multiple times a day). One of them is an ERP system that's being used by 10+ people at any given time. There's a decent amount of traffic to the server, but it seems to be handling it fine (no issues found in the Task Manager). This Pocket PC is the only device that uses the "ProgramZDatabase". I am unaware of any backups or reports that are taking place during these errors. I don’t see anything in the logs, unless I’m just looking in the wrong places. None of the configurations in the SQL server have been touched in years.

In another forum someone mentioned that I might need to check into a connection timeout. I’m a little new to connection timeouts; is that something I should look into? How would I check and adjust the timeout? I’ve played with timeouts in the connection string, but no luck.
Richard Deeming 11-Nov-15 16:28pm    
Is the exception message really "SqlException", or did you remove the real message from your post?
Member 12132382 11-Nov-15 17:02pm    
Surprisingly it really is just "SqlException".
Richard Deeming 11-Nov-15 16:38pm    
Error number 6 seems to map to ERROR_INVALID_HANDLE. Could this be a connection pooling[^] issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900