Threads and Accessing MySQL

Hi,

I have a function which when called triggers a thread. The function
returns after starting the thread.

Thread should access database update few tables and then should end. But
I am getting an error when Thread tries to access the database:

Mysql::Error: Lost connection to MySQL server during query: BEGINe[0m

Do i have to open up a new database connection for threads? If so how do
I do it?

Any suggestions?

Regards,
Sandeep G

And if i don’t invoke this thread, whole app works fine. So MYSQL
connection is intact in main thread, but on spawned thread hits the
block with:
Mysql::Error: Lost connection to MySQL server during query: BEGINe[0m

Sandeep G. wrote:

Hi,

I have a function which when called triggers a thread. The function
returns after starting the thread.

Thread should access database update few tables and then should end. But
I am getting an error when Thread tries to access the database:

Mysql::Error: Lost connection to MySQL server during query: BEGINe[0m

Do i have to open up a new database connection for threads? If so how do
I do it?

Any suggestions?

Regards,
Sandeep G

On Mar 26, 6:34 pm, Sandeep G. <rails-mailing-l…@andreas-
s.net> wrote:

And if i don’t invoke this thread, whole app works fine. So MYSQL
connection is intact in main thread, but on spawned thread hits the
block with:
Mysql::Error: Lost connection to MySQL server during query: BEGIN [0m

Have you set ActiveRecord::Base.allow_concurency to true ?

Fred

AFAIK this is a problem with the mysql connector supplied with Rails.
Install mysql gem and then use it in the thread to connect to mysql.
MySQL
new connections are very light weight and hence there should be no
problem
with opening extra connection(I may be wrong here)

On Thu, Mar 27, 2008 at 12:41 AM, Frederick C. <

Frederick C. wrote:

On Mar 26, 6:34�pm, Sandeep G. <rails-mailing-l…@andreas-
s.net> wrote:

And if i don’t invoke this thread, whole app works fine. So MYSQL
connection is intact in main thread, but on spawned thread hits the
block with:
Mysql::Error: Lost connection to MySQL server during query: BEGIN [0m

Have you set ActiveRecord::Base.allow_concurency to true ?

Fred

If I set this in environment.rb, app fails totally :frowning: Below is the
error.
#<NoMethodError: undefined method `requires_reloading?’ for {}:Hash>

I tried doing , ActiveRecord::Base.establish_connection with in thread.
Though it doesn’t fail when i do so, i dont see any actions being
performed on database though.

I am totally lost! How do I set this allow_concurrency? My develoment
machine is windows and I am using webrick.

yes you need to do establish_connection

On Thu, Mar 27, 2008 at 11:40 AM, Sandeep G. <

Piyush R. wrote:

AFAIK this is a problem with the mysql connector supplied with Rails.
Install mysql gem and then use it in the thread to connect to mysql.
MySQL
new connections are very light weight and hence there should be no
problem
with opening extra connection(I may be wrong here)

On Thu, Mar 27, 2008 at 12:41 AM, Frederick C. <

Hi Piyush,

I installed mysql-gem (win32) . Do I need to do some intialization in
the thread before accessing the database?

Regards,
Sandeep G

Is there an easy way to tell if your app is using the mysql connected
supplied with rails? or the compiled version?

Piyush R. wrote:

AFAIK this is a problem with the mysql connector supplied with Rails.
Install mysql gem and then use it in the thread to connect to mysql.
MySQL
new connections are very light weight and hence there should be no
problem
with opening extra connection(I may be wrong here)

On Thu, Mar 27, 2008 at 12:41 AM, Frederick C. <