c# - Executing sql file with multiple statements -
i'm wanting execute bunch of sql files , i'm having problems (i think) files have multiple statements in them. see here:
trying execute sql throws exception:
"at mysql.data.mysqlclient.mysqlcommand.executereader(commandbehavior behavior) @ mysql.data.mysqlclient.mysqlcommand.executenonquery()"
i'm using mysql connectors , i'm not doing modification strings , reading them file.
using (mysqlconnection conn = new mysqlconnection()) { try { conn.connectionstring = connect_str; conn.open(); console.writeline("\n[executing] " + file); string sql = file.readalltext(file); if (sql != null && !sql.equals("")) { debug.writeline(sql); mysqlcommand command = new mysqlcommand(sql, conn); command.commandtext = sql; command.prepare(); command.executenonquery(); } else console.writeline("no sql"); conn.close(); } catch (exception e) { console.writeline("[sql exception] " + e.stacktrace); } }
you must enter connection parameter allow user variables=true make work.
Comments
Post a Comment