2

I have written a code in ASP.NET to fetch data from Oracle database. The code returns data from locally hosted Oracle DB but when I am pointing towards the remote OracleDB, nothing comes. However, if I run same query on the remote DB using SQL Developer Tool, it works fine. I have debugged my code for right SQL statement and it is absolutely correct.

Following is my code snippet

using (Oracle.DataAccess.Client.OracleConnection con = new
Oracle.DataAccess.Client.OracleConnection())
        {
                con.ConnectionString = ConfigurationManager.ConnectionStrings["ca_eFormsVSED"].ConnectionString;
                con.Open();

                // query for fetch username and market
                String sql = "a valid query"

                Oracle.DataAccess.Client.OracleCommand cmd = new Oracle.DataAccess.Client.OracleCommand(sql, con);
                cmd.CommandType = CommandType.Text;
                if (con.State == ConnectionState.Open)
                {
                    Oracle.DataAccess.Client.OracleDataReader dr = cmd.ExecuteReader();
                }
                if (dr.Read())
                {
                   //Do Something
                }
        }

Please suggest how to make it work.

4
  • There must be some connectivity issue between your machine and remote DB. Commented Oct 15, 2015 at 14:19
  • You have omitted too much. I guess you are using parameters, show them and the query. Also, this won't compile at all because you create the OracleDataReader in the if and use it outside. We can't help to fix your issue if you don't show the code that causes it. Commented Oct 15, 2015 at 14:21
  • if(try to ping your remote server && check your tnsnames.ora file&&check the conncetionstring&&check the query){//program must execute} Commented Oct 15, 2015 at 15:56
  • my connection string is correct because I login successfully from database. Anyway, now I have solution for my problem and I solved it. Commented Oct 16, 2015 at 6:44

1 Answer 1

3

I got the solution of this problem and it may help some one else. If you are 100% sure that code is correct and current SQL statement returns data from database, then check carefully your database tables have dependency or not. Remove existing tables and import new data again and it works fine for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.