Using SQLConnection in C# to connect to a database

  • Thread starter Thread starter David cox
  • Start date Start date
D

David cox

I have written a very simple test program in C# to connect to a
database. It displays a button. When the user clicks the button it
invokes the code below to connect to the database.

This works fine in the emulator but I get a SQLException when I run it
on the Pocket PC from its cradle. The network connection seems fine
because I can use IE to get web pages using the Pocket PC. What is
strange about this is that it was working fine 3 days ago when the
Pocket PC was in its cradle. Now it doesn't. The only thing that
happened between then and now is that I installed MS Office XP.

Do you think I should reinstall VS.NET 2003? Anyone else experience
this problem? Any thoughts or suggestions are most welcome.

David

private void button1_Click(object sender, System.EventArgs e)
{
System.Data.SqlClient.SqlConnection cn = new SqlConnection();

cn.ConnectionString = "myconnectionstring";
try
{
cn.Open();
if (cn.State == ConnectionState.Open)
{
MessageBox.Show("Connection is open");
cn.Close();
}
}

catch (Exception excp)
{
MessageBox.Show("Exception: " + excp.Message);
MessageBox.Show("Base Exception: " +
excp.GetBaseException().Message);
}
}
 
I don't know why it changes.
however I notice it's safer to use IP addresss instead of hostname to
describe server location...
 
Back
Top