List:MySQL and .NET« Previous MessageNext Message »
From:cchany Date:November 3 2004 5:10pm
Subject:Create table with foreign key error with Beta 2?
View as plain text  
I haven't seen this error in beta 1. I have a sql script where I put several
create table statements in there. In my C# program, I read the whole script
into a string and set it as the MySqlCommand's CommandText. When I call
ExecuteNonQuery, it gives me the following error:

  #HY000Can't create table '.\mydb\usertbl.frm' (errno: 150)

Running the same script through the sql command line produces no error. If I
remove all the foreign key constraints from the sql script, it works fine in
the code. Adding in any foreign key constraints, it fails. The problem
didn't exist in the beta 1 connector.

Here is an excerpt of my code (I've removed some error checking code to make
it shorter):

  MySqlConnection conn = null;
  MySqlCommand command = null;
  string cmd = null;
  using (StreamReader sr = new StreamReader("mydb.sql")) {
    cmd = sr.ReadToEnd();

  MySqlConnection conn = new MySqlConnection(myconnstring);
  MySqlCommand command = new MySqlCommand(cmd, conn);
  command.ExecuteNonQuery();  // <- exception thrown here

Does anyone have an idea what's causing this? Any work around or I've done
something terribly wrong? Any help is appreciated.

Create table with foreign key error with Beta 2?cchany3 Nov