CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Inconsistent "no database selected" Error on Contact Create
Pages: [1]

Author Topic: Inconsistent "no database selected" Error on Contact Create  (Read 1625 times)

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Inconsistent "no database selected" Error on Contact Create
May 03, 2012, 09:52:10 am
I'm getting some very inconsistent error when using Contact Create.  At what seems to be random points in my data set, the API will return the following result (in non-debug mode):
Code: [Select]
Array
(
    [is_error] => 1
    [error_message] => DB Error: no database selected
    [tip] => add debug=1 to your API call to have more info about the error
)

I really do not see a pattern as far as what input causes it - the only consistent thing I see is it seems to happen when pulling Custom Groups from the DB (on a select).  If I run the same data set through again, it fails on a different contact (while successfully processing the one it failed on before).  And, it seems the contacts it fails on are ones that were previously in the database.

I'm having a hard time debugging it.  I would love to get some help from the pros if I could.  Here is the output with debug on.  I have starred out the database password, but left everything else as-is.  Would some one mind looking at it and pointing me in the right direction?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Inconsistent "no database selected" Error on Contact Create
May 03, 2012, 09:57:24 am

how large is the dataset and how long does the script run approx before returning an error?

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Re: Inconsistent "no database selected" Error on Contact Create
May 03, 2012, 10:06:57 am
The data set varies, but usually around 50-60 records at a time.  The script stops at random times, so it's hard to say how long - this last run, it processed about 38 contacts before it failed.  Other times, it failed quicker (again, because the second time around, it processes the one it just failed on, so it may be getting further each time, I should put a counter on it to debug).

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Re: Inconsistent "no database selected" Error on Contact Create
May 03, 2012, 10:14:52 am
Also, as far as processing time, it takes about 30secs before a failure.  Now stopping more consistently at the 57th or 58th record (out of 68 on this run).

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Inconsistent "no database selected" Error on Contact Create
May 03, 2012, 10:17:46 am

if i had to guess this is a mysql parameter and the connection is being dropped/closed/aborted. However i dont know a lot about the parameters that control this :(

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Re: Inconsistent "no database selected" Error on Contact Create
May 03, 2012, 10:21:52 am
Hmm, usually "no database selected" in MySQL means we have a connection, but didn't select an actual DB within the server connection.  And from what I can tell in the output, we send the database.

Can you point me to where the "no database selected" error is being sent out?  I'd like to debug and get the actual MySQL error code thrown.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Inconsistent "no database selected" Error on Contact Create
May 03, 2012, 10:25:13 am

do a grep -r in the packages/DB* directory to find out where that error message is thrown

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Inconsistent "no database selected" Error on Contact Create
May 11, 2012, 07:09:56 am
I've sometimes had a message like that in my drush scripts when I'm mixing between civicrm and drupal calls. Specifically, some functions  (e.g. t()) make drupal database calls, and since I always keep civicrm and drupal in different databases, that makes trouble.

I wonder if your script is somehow implicitly triggering a db change? Another example is error logging, which both drupal and civicrm might be doing implicitly.

In this specific case, since you're creating a contact, I'd wonder if some kind of user creation/checking code is switching to your cms database and not switching back, etc.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Inconsistent "no database selected" Error on Contact Create

This forum was archived on 2017-11-26.