Oracle Connectivity

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cpiyush
    New Member
    • Jan 2007
    • 31

    Oracle Connectivity

    Hi. I am using Cx_Oracle inteface for conectivity to Oracle db server.

    This is my code.
    connection = cx_Oracle.conne ct("sys/demo@Sample.Nat as1 as sysdba")
    cursor = connection.curs or()
    cursor.arraysiz e = 50
    cursor.execute( """select col1, col2 from tab1""")
    for column_1, column_2 in cursor.fetchall ():
    print "Values:", column_1, column_2


    & When i am running this I am getting this error: -
    cx_Oracle.Datab aseError: ORA-12154: TNS:could not resolve service name

    Can you please tell me what to with this??

    Thanks & Regards,
    Piyush.
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #2
    verify your database or server name is correct and that it can be resolved by DNS. Also take a look at here

    Comment

    • cpiyush
      New Member
      • Jan 2007
      • 31

      #3
      Originally posted by ghostdog74
      verify your database or server name is correct and that it can be resolved by DNS. Also take a look at here
      I read this & the db name is correct.
      can you tell me wher to check the server name?

      Comment

      • ghostdog74
        Recognized Expert Contributor
        • Apr 2006
        • 511

        #4
        Originally posted by cpiyush
        I read this & the db name is correct.
        can you tell me wher to check the server name?
        sorry, I don't really use oracle. But here's what you can do.
        just remove the other lines, and only left this line:
        Code:
        connection = cx_Oracle.connect("sys/demo@Sample.Natas1 as sysdba")
        if you still get the error, its got something to do with the connection string.
        OR, you can use the makedsn() method to create a connection string for your use. check the docs on how to use it. make sure Sample.Natas1 is in your TNS entry (from the Oracle names server or tnsnames.ora file).

        Comment

        • cpiyush
          New Member
          • Jan 2007
          • 31

          #5
          Originally posted by ghostdog74
          sorry, I don't really use oracle. But here's what you can do.
          just remove the other lines, and only left this line:
          Code:
          connection = cx_Oracle.connect("sys/demo@Sample.Natas1 as sysdba")
          if you still get the error, its got something to do with the connection string.
          OR, you can use the makedsn() method to create a connection string for your use. check the docs on how to use it. make sure Sample.Natas1 is in your TNS entry (from the Oracle names server or tnsnames.ora file).
          Hey Thanks man.
          I have got solution... After some brain storming. Now I am using makedsn() function & its creating the connection without any error. The code is as follows: -

          host = 'localhost'
          port = 1521
          dbase = 'Sample'
          login = 'demo'
          passwrd = 'demo'
          dsn = cx_Oracle.maked sn(host, port, dbase)
          connection = cx_Oracle.conne ct(login, passwrd, dsn)


          But Now I have some other problem.
          I have created this user 'demo' & granted all the privileges to it. But when I am logging thru this & accessing that table, then its saying ORA-00942: table or view does not exist.

          You said You dont use Oracle, but can you suggest me soething on this??

          Comment

          • ghostdog74
            Recognized Expert Contributor
            • Apr 2006
            • 511

            #6
            Originally posted by cpiyush
            Hey Thanks man.
            I have got solution... After some brain storming. Now I am using makedsn() function & its creating the connection without any error. The code is as follows: -

            host = 'localhost'
            port = 1521
            dbase = 'Sample'
            login = 'demo'
            passwrd = 'demo'
            dsn = cx_Oracle.maked sn(host, port, dbase)
            connection = cx_Oracle.conne ct(login, passwrd, dsn)


            But Now I have some other problem.
            I have created this user 'demo' & granted all the privileges to it. But when I am logging thru this & accessing that table, then its saying ORA-00942: table or view does not exist.

            You said You dont use Oracle, but can you suggest me soething on this??
            from your error , you can easily guess that its a table/view problem. Is your table or view called tab1 (from previous post) created in "Sample" database?

            Comment

            • cpiyush
              New Member
              • Jan 2007
              • 31

              #7
              Originally posted by ghostdog74
              from your error , you can easily guess that its a table/view problem. Is your table or view called tab1 (from previous post) created in "Sample" database?
              Yes. This table 'tab1' is created in db named 'Sample'.
              & I have given all the privileges to user 'demo' on this table.
              But all these privileges are not getting refelected when I am logging thru 'demo' & trying to execute 'select' stament.

              My basic problem is coming here that I am create a user---> granting all the privileges---> Logging in thru that user ---> Trying to execute those privileges (But those privileges are not getting refelected )

              Comment

              • ghostdog74
                Recognized Expert Contributor
                • Apr 2006
                • 511

                #8
                Originally posted by cpiyush
                Yes. This table 'tab1' is created in db named 'Sample'.
                & I have given all the privileges to user 'demo' on this table.
                But all these privileges are not getting refelected when I am logging thru 'demo' & trying to execute 'select' stament.

                My basic problem is coming here that I am create a user---> granting all the privileges---> Logging in thru that user ---> Trying to execute those privileges (But those privileges are not getting refelected )
                well, its beyond my means now. The last thing i suggest is to log in to Oracle using its client interface (SQL plus or something) and see if you really cannot select from tab1.

                Comment

                Working...