tags:

views:

201

answers:

2

Is there a way to run an arbitrary sql script through ODP.NET? I'd like to do something like this:

SomeOracleObject.RunFile("myfile.sql");

In other words, I want to obviate the need for sqlplus.exe.

+1  A: 

Here's a snippet of code I use to do exactly what you're asking.

    using (OracleConnection conn = CreateConnection(confConnString))
    {
        try
        {
            using (OracleCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = scriptFileContents;

                cmd.ExecuteNonQuery();
Brad Bruce
This doesn't work - when I try to do that, I get an ORA-00911 error as it doesn't like the ; at the end of SQL statements
thecoop
A: 

I have been looking for a similar solution to the problem. I posted on the Oracle forums for ODP.NET but it appears no one from Oracle actually participates in the forums. The closest thing I have seen to this is DevArt's dotConnect for Oracle's OracleScript class. Ideally I want the same functionality I have inside the SQL Server Management Objects, but for Oracle. If I had my choice, I would move back to SQL Server because of things like this - but it's not my choice to make. :(

Colin Bowern