Trouble connecting to SQL Server 2000 from Mobile Device

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having trouble connecting to a SQL Server 2000 server on our network.
The handheld device is connected wirelessly to the network. I can ping the
IP address of our SQL Server from the mobile device. I can get on the
internet using the device. But I get an SQLException when trying to run just
a very simple app
that is suppose to connect to the SQL Server Northwind database. It doesnt
give any error code. Here is my simple app. The app is suppose to just pull
one record and show the record count in a text box on a form but never gets
to that point. It bombs on the connection. Could someone tell me if my
connection string is off or something?

Thanks,
David

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

namespace TestSQL
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.MainMenu mainMenu1;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(32, 40);
this.textBox1.Size = new System.Drawing.Size(184, 22);
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(32, 88);
this.textBox2.Size = new System.Drawing.Size(184, 22);
this.textBox2.Text = "textBox2";
//
// Form1
//
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>

static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
// Connection String for MSSQL Server 200
// Server IP 192.168.251.32, dummy database = WINSTSDB, dummy
user =
sleeptrain
string Connection_String = "Data Source=192.168.251.32;Initial
Catalog=Northwind;User Id=sleeptrain;Password=monkeytrain";
// Setup SQL Connection object
SqlConnection dbConn = new SqlConnection( Connection_String );

// This routine will create a detailed table structure report
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM
dbo.Employees WHERE
EmployeeID = 1",dbConn);

// Define a Data Table object
System.Data.DataTable WinstisTable = new DataTable();


dbConn.Open();
da.Fill( WinstisTable );

this.textBox1.Text = "Count = " +
WinstisTable.Rows.Count.ToString();

dbConn.Close();
da.Dispose();

}
}
}
 
All of your code seems to be in order.

What specific error are you getting? Wrap the connection code in a try
catch block catching a SQLException.

If it is a 'Login failed for user...' error, then chances are your SQL
server user/security is setup wrong. Be sure your SQL server's
authentication is set to 'SQL Server' and your user id 'sleeptrain' has been
granted permission to access the NW db.

TONY
 
Hi Tony,
I actually did try putting it in a try..catch block and the
Exception.Message
value returned was simply "SqlException". No numeric error code or anything.
I was surprised it did not give more details.

I will check the authentication and database permissions.

David
 
If I were you, I would check for firewall problems. Especially if your SQL
Server is running on a Windows XP SP2, then I'm almost sure that the TCP
1433 port is not open. Why don't you check the following:
Is your server accessible to other desktop PCs in your network?
Is there a firewall installed on the server?
Is TCP/IP enabled on your SQL Server?
Is TCP/IP's port open to the outside world?
 
That's because you need to catch a SQLException, not a generic exception.
try
{}
catch(SQLException ex)
{
ex.ToString(); //put a break here and read the message
}

T
 
Thanks Papppp,
It ended up being something way more simple. The user name I was using
had not been used in a long time and I did not have the password correct I
believe. I just created a dedicated user for the handheld, and bam it worked.
If figured that out by creating the same app for desktop and it also could
not connect but it gave me more information in the error than the smartdevice
app did. So I am good now.

Thanks for the help guys.
David
 
Oh yeah and Tony, thats for that information on the SQLException versus
generic. I will use that in the future.

Thanks,
David
 
Back
Top