System.InvalidOperationException: Connection must be valid and open.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Alejandro Penate-Diaz (alejandro_at_apenate.com)
Date: 12/18/04


Date: Fri, 17 Dec 2004 22:06:32 -0500

Hi.

I am using this function tu execute updates to a MySql database from a sql
string, but I am getting a System.InvalidOperationException: Connection
must be valid and open.

Database queries work fine, but I cant update the source. Am I missing
something?

Thanks, Alejandro.

public static bool updateSource(string sql)

{

MySqlConnection conn = new MySqlConnection(myConnectionString);

MySqlCommand command = new MySqlCommand(sql,conn);

command.CommandType = CommandType.Text;

try

{

command.ExecuteNonQuery();

return true;

}

catch (Exception)

{return false;}

finally

{

conn.Close();

}



Relevant Pages

  • Re: System.InvalidOperationException: Connection must be valid and open.
    ... > I am using this function tu execute updates to a MySql database from a sql ... > Thanks, Alejandro. ...
    (microsoft.public.dotnet.framework.adonet)
  • System.InvalidOperationException: Connection must be valid and open
    ... I am using this function tu execute updates to a MySql database from a sql ... but I am getting a System.InvalidOperationException: Connection ... MySqlConnection conn = new MySqlConnection; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Java and mysql together
    ... tutorials etc of just connecting to a mysql database, ... public class sql extends javax.swing.JFrame { ... putting the com and org folders in Security but that had the same problem. ...
    (comp.lang.java.gui)
  • Re: Java and mysql together
    ... > tutorials etc of just connecting to a mysql database, ... > public sql() { ... > putting the com and org folders in Security but that had the same problem. ...
    (comp.lang.java.gui)
  • Re: OT: SQL-isti
    ... I have a quick question r.e. a SQL query. ... into my MySQL database and then move all the data into a central table. ... has a brain-dead optimiser. ... You're right to eschew scripting languages for stuff like this - ...
    (uk.rec.motorcycles)