Question

    OracleConnection conn = new OracleConnection();
    conn.ConnectionString = @"Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.206.0.23)(PORT = 1521)))(CONNECT_DATA = (SID = ORCLWEX3)));User Id= RAMNIVAS_CI;Password= RAMNIVAS_CI;";
    conn.Open();


    SetStatus(null, "CLEARING CI DATABASE");
    OracleCommand com = new OracleCommand(@"set pages 0
                    set lines 80
                    spool c:\delete_objects_CI
                    select 'drop '||object_type||' '||object_name||';'
                    from user_objects;
                    spool off
                    start c:\delete_objects_CI.lst
                    purge recyclebin;
                    set pages 100", conn);
    com.ExecuteNonQuery();

I guess there is some problem in the query I am trying to execute.

Was it helpful?

Solution

You cannot execute SQL*plus commands with the Oracle client. SQL*plus commands are only supported by SQL*plus and some Oracle tools like SQL Developer.

Your code basically iterates over all objects of the current user and then drops them. You should be able to achieve the same with a loop:

OracleCommand userObjCmd = new OracleCommand("select object_type, object_name from user_objects", conn);
OracleDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    OracleCommand dropCmd = new OracleCommand(
        String.Format(@"execute immedidate 'drop {0} \"{1}\"'",
            reader.GetValue(0), reader.GetValue(1)),
        conn);
    dropCmd.ExecuteNonQuery();
}

You will need to add some code for properly closing the command and reader instances and for handling errors.

And you might need to discard errors silently and try to repeat the above code several times until all objects have been successfully dropped since some objects cannot drop as long as other objects depend on it.

OTHER TIPS

You are trying to execute SQL*Plus commands through your driver. I do not think this can be done.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top