Saturday, October 23, 2010

ORA-12514: TNS:listener does not currently know of service requested in connect descriptor


In this post I will try to show how efficiently we can avoid error ORA-12514. My suggestion is whenever you get this error forget about tnsnames.ora and other stuff related to it. Start fixing problem step by step.

Problem Description:

Whenever you try to connect to database the following error comes.
-bash-3.00$ sqlplus arju/a:1522/dba

SQL*Plus: Release 10.2.0.2.0 - Production on Tue Jun 24 06:35:02 2008

Copyright (c) 1982, 2005, Oracle. All Rights Reserved.

ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor

Cause of The problem:

The services named issued with the connection identifier has not been registered yet.

Solution of The Problem:
After getting above error forget any tnsnames.ora file. Issue lsnrctl status command on the server to which you try to connect like,

-bash-3.00$ lsnrctl status

LSNRCTL for Solaris: Version 10.2.0.1.0 - Production on 24-JUN-2008 07:17:56

Copyright (c) 1991, 2005, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC2)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Solaris: Version 10.2.0.1.0 - Production
Start Date 24-JUN-2008 07:01:52
Uptime 0 days 0 hr. 16 min. 4 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /oracle/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC2)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=neptune)(PORT=1522)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "dbase" has 1 instance(s).
Instance dbase, status READY, has 1 handler(s) for this service...
Service "dbaseXDB" has 1 instance(s).
Instance "dbase", status READY, has 1 handler(s) for this service...
Service "dbase_XPT" has 1 instance(s).
Instance "dbase", status READY, has 1 handler(s) for this service...
The command completed successfully

Now closely look at the bolded items above , it is host, port, service and optionally instance.
Now use it in the connection descriptor as follows.

sqlplus user_id/password@host:port/service

Like here,
$sqlplus arju/a@neptune:1522/dbase
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jun 24 07:21:19 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

This method of connecting to database is called Easy Connect Naming Method.

ORA-12560: TNS:protocol adapter error on windows machine while starting oracle


Error Description

On my windows server machine whenever I try to logon to database as a sysdba user it fails with the message ORA-12560.
C:\Documents and Settings\Oracle>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Aug 16 11:01:58 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.

ERROR:
ORA-12560: TNS:protocol adapter error

Cause of The Error
Oracle classify this as a 'generic protocol adapter error'. In my experience while practice the happening of this error oracle indicates that Oracle client does not know what instance to connect to or what TNS alias to use.

Solution of The Problem

1)If you have server running then while connecting to database as a sysdba user ensure that you have set properly your ORACLE_SID variable. Try explicitly set your envionmental variable on windows machine by,

>set ORACLE_SID=db_name

2)Ensure that you have right services running on your database. You can check whether oracle is running or not by right click on taskbar then select task manager and see whether oracle.exe is running or not.

If it is not running then it is likely to get ORA-12560: TNS:protocol adapter error on your windows machine. To avoid this error you have to run the service. You can do it from right click on my computer> select manage> Click on services and Applications> Double click on services> find the service name OracleSERVICE$ORACLE_SID. If your database name is ARJU then find the service name OracleSERVICEARJU and start it.

You can start the service also by command prompt,
C:>sc start OracleSERVICE$ORACLE_SID

Using oradim by,
C:>oradim -startup -sid $ORACLE_SID

After starting try to connect to database as sysdba and likely you will be able to connect to your database.

C:\Documents and Settings\Oracle>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Aug 16 11:03:16 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

3)If you are connecting to a remote database then try easy naming method. Don't try to connect by tnsnames alias. Easy naming method is described in http://dbatutorials.blogspot.com/2010/10/ora-12514-tnslistener-does-not.html

4)Ensure that you are using correct tnsnames.ora and you have correct settings in your tnsnames alias. Whether you have correct tnsnames entry or not you can check that by >tnsping hostname

On unix machine, if you see tnsnames.ora is most likely accurate then at the Unix prompt, echo the TNS_ADMIN environment variable.

% echo $TNS_ADMIN

•If nothing is returned, try to set the TNS_ADMIN environment variable to explicitly point to the location of the TNSNAMES.ORA file.

In C Shell, the syntax is:
% setenv TNS_ADMIN full_path_of_tnsnames.ora_file

In K Shell or bash, the syntax is:
% export TNS_ADMIN=full_path_of_tnsnames.ora_file

On windows machine try setting the environment variable 'LOCAL' to the required connection alias instead. In windows machine environmental variable is set by set keyword.

Now try to connect to database.

5)If you use DHCP to assign I

Microsoft Management Console keyboard shortcuts


Main window keyboard shortcuts

• CTRL+O :Open a saved console.
• CTRL+N :Open a new console.
• CTRL+S :Save the open console.
• CTRL+M :Add or remove a console item.
• CTRL+W :Open a new window.
• F5 key :Update the content of all console windows.
• ALT+SPACEBAR :Display the MMC window menu.
• ALT+F4 :Close the console.
• ALT+A :Display the Action menu.
• ALT+V :Display the View menu.
• ALT+F :Display the File menu.
• ALT+O :Display the Favorites menu.

MMC console window keyboard shortcuts

• CTRL+P :Print the current page or active pane.
• ALT+Minus sign (-) :Display the window menu for the active console window.
• SHIFT+F10 :Display the Action shortcut menu for the selected item.
• F1 key :Open the Help topic, if any, for the selected item.
• F5 key :Update the content of all console windows.
• CTRL+F10 :Maximize the active console window.
• CTRL+F5 :Restore the active console window.
• ALT+ENTER :Display the Properties dialog box, if any, for the selected item.
• F2 key :Rename the selected item.
• CTRL+F4 :Close the active console window. When a console has only one console window, this shortcut closes the console.

Friday, October 15, 2010

Catchable fatal error: Object of class WP_Error could not be converted to string

Problem Description
In the environment of
WPMU 2.9.2
BP 1.2.3
PHP 5.2.13
BuddyPress Groupblog 1.4.4
the buddypress groupblog accessing blog tab fails with error below.
Catchable fatal error: Object of class WP_Error could not be converted to string in /home/kunstfac/public_html/wp-includes/wp-db.php on line 488 
The url will be like, http://{website_name}/groups/{group_name}/blog/

Cause of the problem
The problem happened due to bug of BuddyPress Groupblog version 1.4.4.

Solution of the problem
Since this is bug of this BuddyPress Groupblog 1.4.4 version so it is expected bug will be resolved in the next version of this plugin. However you can follow following workaround to make the plugin or blog section work.

The idea is don't create the group and groupblog at the same time.

Step 01: Visit the Site Admin > Blogs. Create a new Blog. Ensure that blog is created by visiting wp-admin/wpmu-blogs.php

Step 02: From the frontend after login as admin Create a group as usual but do not create a new groupblog. Instead at 3. Group Blog click the checkbox "Enable group blog" and then Use one of your own available blogs and from dropdown box select your blog.

Step 03: Go through next steps and you will see your blog is working perfect.

How to enable theme and plugin editor for wordpress mu

After you install and login for first time in wordpress mu you will be astonished that under Appearance tab there is no longer present an "Editor" link and under under Plugins section there is no longer present "Plugin Editor" on Dashboard in WPMU. So you might wonder how you will change a theme or plugin or a stylesheet file from wordpress.


Following is a screenshot about how you see Appearance section.

You can get the editor by installing plugin or manually changing files in wordpress.

Installing Enable Theme and Plugin Editor (WPMU) plugin
You can get theme and plugin editor by simply,
- Login to Wordpress dashboard as site administrator.
- Under Plugins tab click on Add New.
- Install Plugin window will appear. You will see Search for plugins by keyword, author or tag.
- Choose Term from drop down menu, in the textbox type "Enable Theme and Plugin Editor" and then search Plugin. You will see "Enable Theme and Plugin Editor (WPMU)" there. Just install it and activate the plugin. You will see your editor for theme and plugin will appear in wordpress MU.

Manually Installing Enable Theme and Plugin Editor (WPMU) plugin

- Download the "Enable Theme and Plugin Editor (WPMU)" plugin from http://wordpress.org/extend/plugins/enable-theme-and-plugin-editor/.

- Using an FTP editor upload the plugin file(s) or folder to the /wp-content/plugins folder.
- Login to Wordpress dashboard as site administrator and click on Plugins.
- You should see your new Plugin listed. To turn the Plugin on, click Activate on the far right side of the list.
- After you activate you will see theme and plugin editors are enabled and you can modify files within wordpress admin panel.

Manually changing Wordpress files
- Go to wp-admin/includes folder of your Wordpress MU installation directory.
- You have to edit the mu.php file. Open the mu.php file with any editor software and search for the term "unset( $submenu['themes.php'][10]"); " and "unset( $submenu['themes.php'][10] );" . You have to comment both of these two lines.

So, before changes
unset( $submenu['plugins.php'][15] ); // always remove the plugin editor unset( $submenu['themes.php'][10] );  // always remove the themes editor 
And After Changes
/* unset( $submenu['plugins.php'][15] ); */ // always remove the plugin editor /* unset( $submenu['themes.php'][10] ); */ // always remove the themes editor 

- After you commented above two lines, you should be able to see the theme editor and plugin editor option but still those pages will not accessible. To overcome that, you need to make below changes in mu.php file.

Search for the term "if ( strpos( $_SERVER['PHP_SELF'], 'user-new.php'" inside mu.php file you will see following Before Changes lines. Then you need to make it like After Changes.

Before Changes
$pages = array( 'theme-editor.php', 'plugin-editor.php' ); foreach( $pages as $page ) {     if ( strpos( $_SERVER['PHP_SELF'], $page ) ) {         wp_die( __('Page disabled by the administrator') ); 
After Changes
$pages = array( 'theme-editor.php', 'plugin-editor.php' );   foreach( $pages as $page ) {      if ( strpos( $_SERVER['PHP_SELF'], $page )&& !is_site_admin() ) {          wp_die( __('Page disabled by the administrator') ); 
Now check on your Wordpress MU dashboard. You will find the theme editor and plugin editor is working properly in your MU installation.

How to install a Wordpress theme

In the post Introducing wordpress theme I have already discussed about wordpress theme. Now in this post I will discuss how we can install and activate a wordpress theme.

Whenever you install wordpress you already have noticed that there is a default blue style theme and a WordPress Classic 1.5 by Dave Shea. But for your website you of course will try some good and attractive theme. Following steps will help you.

Automatic Installation of Wordpress theme using Wordpress Administration Panel.

Step 01.
Log in to the WordPress Administration Panel.
Step 02. Select the Appearance panel, then Themes.
Step 03. Select Add New Themes
Step 04. Use the sub-menu or the Search or Filter options to locate a theme you would like to use.
Step 05. Click on the Preview link to preview the theme.
Step 06. If you are satisfied with the preview use the Install link to upload the theme to your blog. You may need to provide your ftp information in this phase.

Step 07. After you install wordpress theme you will get a message like below.
Downloading install package from http://wordpress.org/extend/themes/download/......zip Unpacking the package. Installing the theme. Successfully installed the theme ................ Actions: Preview | Activate | Return to Theme Installer 
You will have three options. Now you need to click on Activate to apply the theme.
Alternatively, you can activate your theme from http://domain_name/wp-admin/themes.php

Manual Installation of wordpress theme
Step 01: Choose a theme to use for your site.
At first you need to find out suitable themes for your website. There are lots of free and paid wordpress themes. You can either google it or you can find it from wordpress site. After you choose the suitable theme download the theme zip file.

Step 02: Extract the theme zip file.
Once you download the theme extract the zip file using unzip or unrar utility. Review the readme.txt and any screenshot of the template. There might also have index.html file.

Step 03: Upload the theme directory into wordpress wp-content/themes folder.
After you download and extract the theme folder upload the theme folder into wordpress site's wp-content/themes directory. For example if you theme name is SkyTheme then all theme files will under under sitename/wp-content/themes/SkyTheme. You can use ftp or ssh to upload the theme files. FileZilla is an example of good ftp client software.

Step 04: Activate the theme.
The theme files are uploaded and now you need to activate the theme. To activate the theme.
- Log in to the WordPress Administration Panel.
- Select the Appearance panel, then Themes.
- From the Available Themes section, you will see your theme. Click on the theme title (or theme screenshot) for the theme you wish to activate.
- A preview of the theme will be shown.
- To activate the theme click the Activate "Theme Name" link in the top right.

Note that, if the theme preview is blank, do not activate the new theme without investigating further. Your site may not be displayed correctly, otherwise.

Fatal error: Allowed memory size of 33554432 bytes exhausted

Problem Description
In the wordpress dashboard Plugins, Incoming Links section does not load and loading fails with message,
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 1966080 bytes) in /home/nextlew4/public_html/arju-on-it.com/wp-includes/class-simplepie.php on line 5409

Also, whenever you try to upgrade any plugin it fails with message,
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2350382 bytes) in /home/nextlew4/public_html/arju-on-it.com/wp-includes/http.php on line 1365

Cause of the Problem
From the wordpress release of 2.5, within wp-settings.php file there is parameter WP_MEMORY_LIMIT which allows you to specify the maximum amount of memory that can be consumed by PHP. The default value for WP_MEMORY_LIMIT is limit to 32MB. So by default, WordPress will attempt to increase memory allocated to PHP to 32MB (you can find this code at beginning of wp-settings.php).

Note that, this setting imposes memory limit to usage memory of PHP only for WordPress, not other applications.

Solution of the Problem
If wordpress PHP needs more memory than the value set inside wp-settings.php you will receive a message such as "Allowed memory size of xxxxxx bytes exhausted".

So the setting in wp-config.php should reflect something higher than 32MB.

You will find the wp-config.php file under wordpress home installation directory. If you open the file you will see the following lines at the beginning of the file.

if ( !defined('WP_MEMORY_LIMIT') )
define('WP_MEMORY_LIMIT', '32M');


Increase the limit to somewhere bigger value. For example to increase PHP Memory to 64MB

define('WP_MEMORY_LIMIT', '64M');

Increase PHP Memory size to 100MB
define('WP_MEMORY_LIMIT', '100M');

Please note that, this setting may not work if your host does not allow for increasing the PHP memory limit. If after increasing limit from wp-settings.php you still get "Fatal error: Allowed memory size of 33554432 bytes exhausted" contact your host to increase the PHP memory limit. Note that many hosts set the PHP limit at 8MB.