Which account to use when connecting to Oracle DB from script?

Posted on 2011-02-27
Last Modified: 2013-12-19

please can somebody help me with the following?
I'm trying to connect to Oracle from PowerShell script. I believe the only problem is in the incorrect connection string and I don't know, which user account should be used in the string.

The hostname is ORA1 and there I have only the default database called "orcl".
If I use lsnrctl status, it displays the info about runninc instance "orcl", so I think this shouldn't be a problem.
I'm able to connect to database from sqlplus. I know almost nothing about Oracle, but it seems that I can connect successfully if I use the username "sys as sysdba".
I set all the passwords to be "abc" just for simplicity.

I doesn't let me in if I use the account sysdba directly - it works only as "sys as sysdba".

Now regarding the script - it's almost the same. If I have "sys" in the connection string, I get an error message saying "you should use 'sys as sysdba' as logon name".
If I change it in the connection string and use the username "sys as sysdba", then I get an error message about incorrect password/logon denied.

Could you please tell me how to fix it? I read hundred of pages about the connection strings, tried multiple combinations, but no avail so far.

Also I'm not sure what value should be in the connection string in "data source". I have "ora1\orcl", which is the hostname\db_name. Should I use something different?

Thank you very much in advance.

Question by:martin_babarik
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 74

Expert Comment

ID: 34991745
sqlplus sys/abc@orcl as sysdba
LVL 74

Expert Comment

ID: 34991750
if you are logged in as the oracle owner (usually a user called "oracle")

sqlplus / as sysdba
LVL 13

Author Comment

ID: 34991968
Hi and thank you for the comment.

What you say works nice with sqlplus - I connect successfully.

But the question was more about what should be passed in the connection string. I realize I'm asking about scripting in the Oracle zone, but I believe the connection string is the same for any programming/scripting language.

I'm logged on as local administrator, it's a fresh install of Windows Server 2003 and Oracle, all default, only the password is set to 'abc'.

This problem is driving me crazy as I need to develop quite complex script and I'm stucked just first few lines where I have the connection attempt.

As long as I'm able to work with the database using sqlplus, I believe the database, services and listener are ok. Maybe it's something wrong with my script, but it's just a sample code googled on the Internet, nothing special, see below.

The table 'employees' probably doesn't exist, but didn't get so far to get an error message about this :-) It's just about the connection.

Thanks a lot.

$connectionString= "Data Source=ora1/orcl;User Id='sys/abc@orcl as sysdba';Password=abc;"
$connection = New-Object System.Data.OracleClient.OracleConnection($connectionString)
$command = new-Object System.Data.OracleClient.OracleCommand($queryString, $connection)
$employeesNames = $command.ExecuteScalar()
echo "Number of employees: "$employeesNames

Open in new window

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.


Accepted Solution

jaiminpsoni earned 250 total points
ID: 34992358
what is the script?

Is it perl script? Or jython script or python script? (I am not much into it, so cant figure it from sample code)

For JDBC, we have following option...

 * user                String   The user name for logging into the
 *                                         database.
 * password            String   The password for logging into the
 *                                         database.
 * database            String   The connect string for the database.
 * internal_logon     String   A role, such as SYSDBA or SYSOPER,
 *                                         that allows you to log on as SYS.

But this is with JDBC, it will be different for string, but the property should remain same for all the DBC.

so try exploring more on internal_logon syntex for your scripting language...
LVL 12

Assisted Solution

by:Praveen Kumar Chandrashekatr
Praveen Kumar Chandrashekatr earned 250 total points
ID: 34992369
why you want to login as sys any particular reason?

if not why cann't you try as system user... if you know system password.

if you don't know the system password login to database with sys through sqlplus and change the password of system.

alter user system identified by password account unlock;

then you can use system user in your script.
LVL 13

Author Comment

ID: 34992557
Jaiminpsoni: The script is powershell, but I could do it using any other language I know...ehm, actually VBScript, that's all :-)
Maybe there could be the concept I don't understand - the difference between user and internal_logon.

Praveencpk: I don't need to login as sys - as I mentioned I don't know Oracle and I thought, that this is the simplest way, when I'm working in the virtual environment just for development purposes - that I will not be limited by some restrictions or insufficient privilegues.

By system user you mean a user called "system"? I altered the system user by using your command, went ok, I can login from sqlplus using this account.

Actually as I can see now, the script works! I modified the connection string to be like below and used OleDB from another googled example:
$connString = "password=abc;User ID=SYSTEM;Data Source=orcl;Provider=OraOLEDB.Oracle"

Afaik I haven't tried to login with SYSTEM user account before, maybe this was the core of the problem.

Anyway thank you very much for your help guys, I'm gonna close this question and split the points....and ask some new questions :-)


Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question