Welcome Guest, Not a member yet? Register   Sign In
Database connection error, randomly?! [SOLVED]
#1

[eluser]dootzky[/eluser]
Hi guys,

I'm developing in CI for over a year now, and I love it.
Lately, I'm having problems on some of my servers, where projects are working fine, but if you navigate trough links "too fast" (whatever that means), sometimes instead of showing me the right page, CI gives me database error, saying that it can't connect to database with the given settings.

Then I refresh the page, and everything works.

My question is - why I am getting this random error, let's say 5 times out of 30 page-views?

Should I know something about closing the CI database-connection?
Is CI closing the DB-connection by itself, or should I do something about it?

Is there anything I could check, so I could be sure I'm not leaving possible opened db connections, and confusing the production server somehow?

Also, on my local Linux machine, I never have this problem. Only on production servers.

Any thoughts? Smile

Thanks for your time!!
Dootzky
#2

[eluser]dootzky[/eluser]
anybody?
#3

[eluser]Pascal Kriete[/eluser]
CI will close the connection automatically. The exception are persistent connections, which PHP won't close (hence the name).

Try setting pconnect to false in your database config file.
#4

[eluser]dootzky[/eluser]
alright Pascal!

Thanks a lot for the tip, I'll try this now, and see if it helps.

Thanks again for your time.
dootzky
#5

[eluser]sagalout[/eluser]
Hi, Did you manage to solve this? I have exactly the same problem with a site I've just launched.

Works fine on local dev server, but live I just get random occasions where it wont connect to the database. Other installation of CI still work fine on the same server.

Its driving me nuts lol

Edit - tried setting pconnect to FALSE but that stopped the database from connecting completely
#6

[eluser]sagalout[/eluser]
Ah, found out what the issue was. Was actually a server config problem, with too many mysql conenctions. I added this into my.cnf and all is working fine now:

max_connections=2048
#7

[eluser]dootzky[/eluser]
Hi all,

YES, I think this solved the problem. I can't be 100% sure, because the error it self was quite random, but now I've opened like 20 FF-tabs of different pages on my project (on live server), and reloaded ALL tabs at the same time, and none of them broke the database connection, so I guess it's working fine now! Smile

Great job!
Thanks again Pascal!!

[SOLVED]
#8

[eluser]The Wizard[/eluser]
OK HERE WE GO

i removed ALLLLL load->database's from the INDEX and CONSTRUCTORS of my app,
removed the pconnect, added the max_conn, and now its working fine Smile
#9

[eluser]The Wizard[/eluser]
ok update:

first of all, this F%&/ing error keeps just coming again Smile
dunno why but what ive learned:

1.) there is no reason to be stubborn and stick with default $this->db->..
If you have to connect to more then 1 DB, use something like

$DB1 = $this->load->database( 'DBNAME', TRUE );

2.) actually, its a good practice to update the database macros, if you have
any, and use them like this.

3.) i'm exhausted, gotta take a break Smile




Theme © iAndrew 2016 - Forum software by © MyBB