# SQLite3 Exception

**URL:** <https://www.ruby-forum.com/t/sqlite3-exception/185649>\
**Category:** Ruby\
**Created:** [March 24, 2010, 3:17am UTC](https://www.ruby-forum.com/t/sqlite3-exception/185649 "2010-03-24T03:17:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miles\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Miles\_S](https://www.ruby-forum.com/u/Miles_S)\
**Post date:** [March 24, 2010, 3:17am UTC](https://www.ruby-forum.com/t/sqlite3-exception/185649/1 "2010-03-24T03:17:17Z")

</div>

I have a simple IRC Bot that’s running with ActiveRecord and a small  
SQLite3 DB.

When I run as root, the db can be accessed fine, however, when I run it  
as a normal user, I get a SQLite3::SQLException: unable to open database  
file: error.

Now I’ve already chmoded the DB to 0777 and set the owner to the user in  
question, however the issue still remains.

Any ideas?

---

<div class="post-metadata">

**Author:** ![Miles\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Miles\_S](https://www.ruby-forum.com/u/Miles_S)\
**Post date:** [March 24, 2010, 5:10am UTC](https://www.ruby-forum.com/t/sqlite3-exception/185649/2 "2010-03-24T05:10:16Z")

</div>

On Mar 23, 8:16 pm, Miles S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a simple IRC Bot that’s running with ActiveRecord and a small SQLite3 DB.
> 
> When I run as root, the db can be accessed fine, however, when I run it as a normal user, I get a SQLite3::SQLException: unable to open database file: error.
> 
> Now I’ve already chmoded the DB to 0777 and set the owner to the user in question, however the issue still remains.
> 
> Any ideas?

Permissions on the directory owning the DB?

---

<div class="post-metadata">

**Author:** ![Miles\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Miles\_S](https://www.ruby-forum.com/u/Miles_S)\
**Post date:** [March 25, 2010, 4:50am UTC](https://www.ruby-forum.com/t/sqlite3-exception/185649/3 "2010-03-25T04:50:52Z")

</div>

On Tuesday 23 March 2010 09:16:44 pm Miles S. wrote:

> When I run as root, the db can be accessed fine, however, when I run it as  
> a normal user, I get a SQLite3::SQLException: unable to open database  
> file: error.

What happens when you try to access the file with the sqlite3 binary? Or  
with,  
say, the ‘file’ command? Are you sure it’s a Unix permission issue?

> Now I’ve already chmoded the DB to 0777

Don’t do that. Ever.

EVER.

> and set the owner to the user in  
> question,

Do that and set the DB to, say, mode 0600. That should be plenty.

> however the issue still remains.
> 
> Any ideas?

Phrogz had a good idea with checking the directory, or parent  
directories.

---

<div class="post-metadata">

**Author:** ![Miles\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Miles\_S](https://www.ruby-forum.com/u/Miles_S)\
**Post date:** [April 6, 2010, 7:16pm UTC](https://www.ruby-forum.com/t/sqlite3-exception/185649/4 "2010-04-06T19:16:44Z")

</div>

On Thu, Mar 25, 2010 at 12:50:07PM +0900, David M. wrote:

> Don’t do that. Ever.
> 
> > Any ideas?
> 
> Phrogz had a good idea with checking the directory, or parent directories.

It will be the permissions on the directory. SQLite needs to write its  
.journal  
to the same directory in which the db file is located.

enjoy,

-jeremy
