在没有存储过程的情况下从C#Visual Studio执行Alter Tablespace语句

时间:2018-12-15 14:02:22

标签: c# oracle plsql odbc

我需要从C#前端程序添加数据文件或调整数据文件的大小,而数据库中没有任何存储过程。

这怎么办?

Label1.text  =Tablespace name
textbox1.text = location of datafile
textbox2.text = name of the datafile

这是示例代码,但是当我运行它时,我得到一个错误:

  

ORA-00900:无效的SQL语句

代码:

private void button1_Click(object sender, EventArgs e)
{
    string sqla = @"alter tablespace '" + label1.Text + "' add datafile '" + textBox1.Text + "' size " + textBox2.Text +"M";
    OracleConnection conn3 = new OracleConnection(); 
    conn3.ConnectionString = connectform.connectionString;
    conn3.Open(); 
    OracleCommand cmd3 = new OracleCommand("sqla", conn3);
    cmd3.CommandType = CommandType.Text;
    cmd3.ExecuteNonQuery();
    conn3.Close();
}

1 个答案:

答案 0 :(得分:0)

驱动程序是否有ExecuteOracleNonQuery方法?可能值得尝试一下,而不是ExecuteNonQuery

如果没有运气...

我不确定,但是我怀疑是驾驶员无法识别ALTER TABLESPACE

如果是这种情况,您可以尝试将其包装在PLSQL块中并使用EXECUTE IMMEDIATE,例如:

private void button1_Click(object sender, EventArgs e)
{
    string sqla = @"BEGIN EXECUTE IMMEDIATE 'alter tablespace " + label1.Text + " add datafile '" + textBox1.Text + "' size " + textBox2.Text +"M'; END;";
    OracleConnection conn3 = new OracleConnection(); 
    conn3.ConnectionString = connectform.connectionString;
    conn3.Open(); 
    OracleCommand cmd3 = new OracleCommand("sqla", conn3);
    cmd3.CommandType = CommandType.Text;
    cmd3.ExecuteNonQuery();
    conn3.Close();
}

这将从那里的驱动程序“隐藏” ALTER TABLESPACE,而不是呈现一个PLSQL块,它应该很高兴地应对。

相关问题