I've got a console app that connects to a database (using Oracle.ManagedDataAccess) and then tries to execute a bunch of SQL*PLUS scripts located on my local hard drive.
Unfortunately although my app works for simple SQL Statements (SELECTS) it doesn't appear to work for SQL*PLUS.
The Code:
var script = File.ReadAllText("C:\\Automation\\script.sql");
using (var objConn = new OracleConnection(_connectionString))
{
OracleCommand objCmd = new OracleCommand();
objCmd.Connection = objConn;
objCmd.CommandText = script;
objCmd.CommandType = CommandType.Text;
try
{
objConn.Open();
objCmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.WriteLine("Exception: {0}", ex.ToString());
}
finally
{
objConn.Close();
}
}
Script.sql - executes without error in SQL Developer
DEFINE CODE_PATH = C:\Automation
@"&&CODE_PATH\Test.sql"
Test.sql - executes without error in SQL Developer\my app without SQL*PLUS
SELECT ID FROM data.SOME_TABLE WHERE ROWNUM < 100
Error:
ORA-00900: invalid SQL statement at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
What am I missing? Is this even possible?