EBGreen
EBGreen

Reputation: 37720

Query Hangs

Ok, this seems simple but I can't find a solution to save my life. I am trying to do a very simple INSERT query on an Oracle DB. I can log into the DB in TOAD with the same credentials as I use in the code and run the INSERT with no problem, so as near as I can tell there are no permissions issues with the credentials and the query itself is syntacticly correct. When I try to run the below code, it just hangs. No errors or anything. I can see the session pop up in TOAD so as far as I can tell the code establishes the connection with no problem. Here is the code:

        String connStr = "Data Source=DB;User id=<USER>;Password=<PASSWORD>;";
        String query = "INSERT INTO table (fields) VALUES (values)";

        OracleConnection conn = new OracleConnection(connStr);
        conn.Open();
        OracleCommand cmd = conn.CreateCommand();
        cmd.CommandText = query;
        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();
        conn.Close();
        conn.Dispose();

I have also tried using an ADO connection and got the same result. Any ideas are appreciated.

Upvotes: 0

Views: 525

Answers (2)

Mark Roddy
Mark Roddy

Reputation: 27936

Have you committed or rolled back the transaction in Toad? Your application could be waiting on a lock held by your session created by Toad.

Upvotes: 3

Harper Shelby
Harper Shelby

Reputation: 16585

Have you tried wrapping it in a transaction and explicitly committing after the insert? IIRC, Oracle's default semantics are very transaction-oriented, unlike SQL Server's.

Upvotes: 0

Related Questions