Saturday, June 30, 2007

Host Credentials of Your Oracle: Hmmm...

When my Oracle Server was down yesterday, I've found the same problem when trying Oracle for the first time. What's the problem? It's host credentials. When opening Enterprise Manager, one of the database is unavailable and needed to be opened. But, when trying to startup it, I must enter the username and password that have the "log on as batch job" access. Someone who has "log on as batch job" access can startup the database. Wait a minute, here's the step by step to add a account who has special access.
  1. Enter your Control Panel by clicking Start button
  2. Choose Administrative Tools
  3. And then Local Security Policy
  4. There're some options (), open Local Policies
  5. Click User Rights Assignment
  6. Find this policy: Log on as Batch Job
  7. Right click it, Properties
  8. Add User or Group. Add the username who will "log on as batch job" access
  9. Make sure username you've entered is shown in the list. OK.
Actually, what's host credentials? It's username and password for Windows user who creates and owns Oracle Database. In the reality, it connects with user who could run "batch job", executes %ORACLE_HOME%/bin and has an access to the database.

Okey, getting headache when troubleshooting Oracle? Just enjoy it!


Special thanks for Kohar "the Master"

Tuesday, June 26, 2007

ASP .NET to Oracle? Try this...

Here's the algorithm:

  1. Make sure you've installed Oracle Client first
  2. Open Visual Studio .NET and choose in design view
  3. Click Toolbox, Data, and drag SqlDataSource.
  4. Choose Configure Data Source
  5. And then New Connection
  6. Change Data Source into Oracle Database
  7. Enter Server Name with your database name
  8. Don't forget to fill Username and Password
  9. To check whether connection successfull or not, click button Test Connection.
  10. If you see information message box: "Test connection succeeded", it means that you're successfully connected to Oracle and ready to work.
  11. Then click Next
  12. Configure the Select Statement. Select table name or view you wanna show and also some columns too. There're some options like Where, Order by, and Advanced
  13. Click Next and Test Query if you wanna check whether it works well or not.
  14. Finish!
  15. Ready to work!
What about the code? Maybe you can help me to switch it to the code :)....

Wednesday, June 20, 2007

Calling Oracle Stored Procedure in PHP

Okay, in this post we will discuss about PHP again. After connecting to Oracle, we can do some query here. Data Manipulation Language (DML) is the basic of SQL (Structured Query Language). But, what about DML in stored procedure? We will create it!

Before continuing, we must create table first. Just make a simple table. Here is the SQL code:

 create table mytable(
id number (3) not null,
name varchar2 (25) not null,
address varchar2 (25) ,
constraint pk_mytable primary key (id)
);

First, create insert procedure to the table. The parameters are the field we want to insert.

create or replace procedure insert_mytable (pid, pname, paddress)
begin
insert into my_table (id, name, address) values (pid, pname, paddress);
end;

Second, create update procedure to update the record of the table. It’s still using the same parameters.

create or replace procedure update_mytable (pid, pname, paddress)
begin
update my_table set id=pid, pname=name, paddress=adress where id=pid;
end;

The last is creating delete procedure. It is used to delete the data from the table. But, we only need one parameter here.

create or replace procedure delete_mytable (pid)
begin
delete from my_table where id=pid;
end;

The next step is calling procedures we’ve created in PHP. Input parameter we can get from a form in html view.

//connect to Oracle
include(“connection.php”);

//get input
$id = $_POST[‘id’];
$name = $_POST[‘name’];
$address = $_POST[‘address’];

//call stored procedured
$query = “BEGIN insert_mytable (:id, :name, :address); END;”;

//parse the query
$s = ociparse($c, $query);

//binding
ocibindbyname($s, ‘:id’, $id, 32 );
ocibindbyname($s, ‘:name’, $name, 32 );
ocibindbyname($s, ‘:address’, $address, 32 );

//execute the query
ociexecute($s);

Before calling the stored procedure, we must connect to Oracle first. It’s done with including connection.php (connection to Oracle has written in the last post). Get the input parameter and then call it. Don’t forget to parse and bind it. And the last step is executing the query. Okay, send me a email if you want to ask about this. Thanks…

Tuesday, June 19, 2007

SQL Developer: a SQL Editor Alternative

Several weeks ago, I got something special to do. I had to add database name in tnsnames.ora for all workstation in my laboratory. Do you know how many computer in my lab? Seventy-five!!! Although can be done over PDC (Public Domain Controller) and helped by some friends, it’s still very hard to do. Because I’ve to check it one by one.


Actually, there are some sql editor we can use. One of them is SQL Developer. If we use this editor, we no need to set tnsnames.ora file. Just simply type the server IP address and the database name before we log in. This is the screenshot:

Simple? It could be different answer you get when asking this question. Maybe it’s just every man habit. Oke, get the next cool database experience!


special thanks for: mbak Novia and Kohar "the Master"

Monday, June 18, 2007

Database name list in Toad

I catch something for you when doing database lab work. It is a screenshot of Toad as sql editor in Oracle database. Let’s check it out!

Have you ever thought about this? How can the name of each database shown here? Is it a magic? Of course not. This is the result of tnsnames.ora’s hard work. You can open the tnsnames.ora once again in directory you’ve installed Oracle database. In this case, I install it in D:\Oracle\product\10.1.0\Client_1\Network\Admin. You’ll see several lines of code setting like this:

# tnsnames.ora Network Configuration File:

E:\oracle\product\10.1.0\db_1\network\admin\tnsnames.ora

# Generated by Oracle configuration tools.

ORALP =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 10.126.11.15)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ORALP)

)

)

BDL2007=

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 10.126.11.15)(PORT = 1521))

)

(CONNECT_DATA =

(SID = BDL2007)

(SERVER = DEDICATED)

)

)

ORAPBD7 =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 10.126.11.15)(PORT = 1521))

)

(CONNECT_DATA =

(SID = ORAPBD7)

(SERVER = DEDICATED)

)

)


EXTPROC_CONNECTION_DATA =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))

)

(CONNECT_DATA =

(SID = PLSExtProc)

(PRESENTATION = RO)

)

)

List of all database names are mentioned here. Now, you don’t need confuser anymore about the magic combo box at Toad. Oke, see you…

Saturday, June 16, 2007

PHP Connection to Oracle

How to do this? In this post, I'll try to write something make me got a headache for several days. But it's okey, I've solved it and I wanna share to you all. First, we have to install Oracle Client in our computer (will be explained in next post). After that, go to D:\Oracle\Network\Admin and you will find a file named tnsnames.ora. Here is the key of the connection. Open it with text editor you have and now we will see some simple codes here:

$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 10.126.11.15)(PORT = 1521)))(CONNECT_DATA=(SID=ORAPBD7)))";
if ($c=OCILogon("username", "password", $db)) {
echo "Successfully connected to Oracle.\n";
OCILogoff($c);
} else {
$err = OCIError();
echo "Connection failed." . $err[text];

You can find the connection string "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.126.11.15)(PORT = 1521)))(CONNECT_DATA=(SID=ORAPBD7)))" in file named tnsnames.ora. In this connection, the Oracle server has ip address 10.126.11.15 with default port 1521. "ORAPBD7" is the name of database in the server that we'll manipulate later. You can save the php file in your web server (like Apache or IIS). Suppose we save it as "connection.php" and to access this file, type http://localhost/connection.php. If connection successfull, the browser will print "Successfully connected to Oracle.". Unless, you will get a message "Connection failed.".

Okey, it's something I can write for you today. You will find my post in this blog too. Thanks for reading.

Life is full with light of grey. Make it colourful with a pray. Good luck!


Special thanks for my best friend: Abid

It's just the beginning...

We have to try until we can do what we want to do! We all free! Nobody can push us! Remember this, bro! Okey, let's do this...