Connection Unexpectedly Terminated
Hi, I was wondering if anyone could help me with a problem I'm having. I'm trying to connect to a remote database and just submit some select queries. It seems to work fine after it gets going, but I always get an exception stating that the Connection was unexpectedly terminted when I submit the first query. If I just submit the query again, it all works fine after that. Any ideas on what's going on?
Here is my source code:
//some of the needed variables
private MySqlConnection conn;
private DataTable data;
private MySqlDataAdapter da;
//skip some unimportant stuff
private void connectBtn_Click(object sender, System.EventArgs e)
{
if (conn != null)
conn.Close();
string connStr = String.Format("server={0};user id={1}; password=2}; database=ranthali_osc1; pooling=false",server.Text, userid.Text, password.Text );
try
{
this.Cursor = Cursors.WaitCursor;
this.databaseExplorerStatusStripPanel.Text= "Connecting to Database.";
conn = new MySqlConnection( connStr );
conn.Open();
this.databaseExplorerStatusStripPanel.Text = "Connected to " + server.Text;
this.Cursor = Cursors.Arrow;
}
catch (MySqlException ex)
{
this.databaseExplorerStatusStripPanel.Text = "Unable to connect.";
MessageBox.Show( "Error connecting to the server: " + ex.Message );
}
}
private void btnSubmit_Click(object sender, EventArgs e)
{
try
{
data = new DataTable();
da = new MySqlDataAdapter(Query.Text.ToString(), conn);
//MessageBox.Show(da.ToString());
da.Fill(data);
dataGrid.DataSource = data;
}
catch (MySqlException ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (conn!=null)
{
conn.Close();
}
}
Subject
Written By
Posted
Connection Unexpectedly Terminated
February 10, 2005 06:35AM
February 28, 2005 01:12AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.