PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Using SQLConnection in C# to connect to a database

Reply

Using SQLConnection in C# to connect to a database

 
Thread Tools Rate Thread
Old 15-03-2004, 09:54 PM   #1
David cox
Guest
 
Posts: n/a
Default Using SQLConnection in C# to connect to a database


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);
}
}
  Reply With Quote
Old 15-03-2004, 11:23 PM   #2
Lloyd Dupont
Guest
 
Posts: n/a
Default Re: Using SQLConnection in C# to connect to a database

I don't know why it changes.
however I notice it's safer to use IP addresss instead of hostname to
describe server location...

"David cox" <david.cox@us.abb.com> wrote in message
news:96d73d12.0403151354.149936a@posting.google.com...
> 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);
> }
> }



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off