# Da SMF2 a Discourse: problemi nell'importazione degli allegati

**URL:** <https://meta.discourse.org/t/smf2-to-discourse-troubles-importing-attachments/89302>\
**Category:** Support\
**Created:** [6 Giugno 2018, 9:46pm UTC](https://meta.discourse.org/t/smf2-to-discourse-troubles-importing-attachments/89302 "2018-06-06T21:46:17Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [6 Giugno 2018, 9:58pm UTC](https://meta.discourse.org/t/smf2-to-discourse-troubles-importing-attachments/89302/2 "2018-06-06T21:58:42Z")

</div>

I’ve had that trouble before, and fixed it with the code below. For some reason, it always fails on the first connection, but it’ll catch the lost connection and try again.

```ruby
  def mysql_query(sql)
    @client.query(sql, cache_rows: true)
  rescue Exception => e
    puts '=' * 50
    puts "problem with database. Trying again in 5"
    sleep 5
    puts e.message
    @client = Mysql2::Client.new(
      host: DB_HOST,
      username: DB_USER,
      password: DB_PW,
      database: DB_NAME
    )
    @client.query(sql, cache_rows: true)
  end

```

---

_[View the full topic](https://meta.discourse.org/t/smf2-to-discourse-troubles-importing-attachments/89302)._
