Unable to open database file

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to open database file

Steve Rogers
I am working with SQLite code I have developed in .NET 2.0
I have done this development in .NET 2.0 because one of the
installation locations for the database client runs
Windows 2000, controlling a large machine (a beam saw).
The saw was shipped with a computer running Windows 2000,
and has never been upgraded the vendor of the machine. Thus
my .NET code must be able to run on Windows 2000, and since
Windows 2000 supports .NET only up to 2.0, with .NET 2.0.

I've done all my development with .NET 4.0 on a 64-bit
system, but the targeting of the code has been for x64.
I have set the project to use .Net 2.0. I am using
the .Net 2.0 version of the System.Data.SQLite.DLL.

I have demo'd the program to the client w/o my development
system, using an x64 laptop, w/Win7 & .Net 4.0. No problems

The program will run on the following machines at the
client site:

3 each Win 7 32-bit w .Net 4.0
1 each Win2000 32-bit w .Net 2.0

Today I installed the application on one of my client's
computers for the first time (a Win 7 23-bit with
.Net 4.0) in preparation for a complete installation on
all machine.

I installed the following files

// My DLL of application specific stuff
08/26/2014  09:00 PM            59,904 Cut85Db.dll

// The GUI and application rules
08/27/2014  09:46 AM           386,048 Cut85Inventory.exe

// The config file shown below
07/27/2014  04:45 PM             2,014 Cut85Inventory.exe.config

// The interop DLL
07/27/2014  04:47 PM           843,776 SQLite.Interop.dll

// A helper DLL for SQLite
08/26/2014  09:00 PM            12,288 SQLiteDb.dll

// The main SQLite DLL
06/23/2014  09:56 AM           282,624 System.Data.SQLite.dll

// I don't use LINQ in .NET 2.0, so I don't think I need this
// but it's there
03/19/2014  01:54 PM           183,808 System.Data.SQLite.Linq.dll

// Files created by my installer
08/27/2014  11:36 AM            28,627 unins000.dat
08/27/2014  11:35 AM         1,178,825 unins000.exe

The database itself is located in the C:\USERS\PUBLIC
directory of the machine I installed on.

When I ran the application, it ran, and, per design, when not
finding a configured database, provided a dialog to the user
to select the database file.  Then it proceed to run until it
returned the following error:

ERROR ---------------
Timestamp:  2014-09-23T13:13:10.9914213
System.Data.SQLite.SQLiteException:  unable to open database file
System.ApplicationException:  Error in SQLiteDb.LDb3.PrepareCommand.
System.ApplicationException:  Error in SQLiteDb.LDb3.GetDataTable.
System.ApplicationException:  Error in
Cut85Db.Composition.GetFirstFieldResults.
System.ApplicationException:  Error in
Cut85Db.Composition.GetInventoryCoreMaterials.
System.ApplicationException:  Error in
Cut85Db.Composition.GetInventoryCoreMaterialsIT.
System.ApplicationException:  Error in
Cut85Inventory.Rules.FilterInterface_Construct.
---------------------

This is a single exception that has the bubbled back to the
caller.

Reading in order, it says that:
SQLiteDb.LDb3.PrepareCommand threw an exception with the message
'unable to open database file'
it was caught by SQLiteDb.LDb3.PrepareCommand
then caught by Cut85Db.Composition.GetFirstFieldResults
the caught by Cut85Db.Composition.GetInventoryCoreMaterials
then caught by Cut85Db.Composition.GetInventoryCoreMaterialsIT
the caught by Cut85Inventory.Rules.FilterInterface_Construct

When the application starts, I call
var DB = new LDb3(Properties.Settings.Default.DBPath);

This creates my LDb3 (Lite Database sql3 helper) with the
current database path.

In FilterInterface_Construct I call GetInventoryCoreMaterialsIT(DB)
GetInventoryCoreMaterialsIT (with the IT suffix) means it
Gets a list of CoreMaterial names with an internally transacted
method called GetInventoryCoreMaterials. This prepares a query
to return the unique set of CoreMaterials known to the database
(a column in a table called Compositions). Since the query only
returns one column in a DataTable, I call GetFirstFieldResults
with the query.

So I can get a connection from my LDB3 helper object, I can
use the connection to get create a command.  In the process of
getting a DataTable from the query, I call a method PrepareCommand,
which looks like this:

private void PrepareCommand(SQLiteCommand command, string sql)
{
     var errorLocus = GetErrorLocus();
     try
     {
         if (command.Connection.State == ConnectionState.Closed)
             command.Connection.Open();   //  <-Exception thrown here
                                          // with message
                                          // 'unable to open database file'
         if (command.Connection.State != ConnectionState.Open)
             throw new ApplicationException("Connection could not be
opened.");
         command.Parameters.Clear();
         command.CommandText = sql;
     }
     catch (Exception ex) { throw new ApplicationException(errorLocus,
ex); }
}

So it seems that all the SQLite logic up to the point where I attempt to
open the database connection is working, but SQLite cannot open the
connection to the database the user selected by providing the path.

I can open the very same database on the very same machine using SQLite
Expert personal.

What can be going wrong here?



















_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Unable to open database file

Joe Mistachkin-3

Steve Rogers wrote:
>
> Reading in order, it says that:
> SQLiteDb.LDb3.PrepareCommand threw an exception with the message
> 'unable to open database file'
>

Is the database file name a UNC path?  If so, the number of leading
backslashes must be doubled (i.e. four leading backslashes are now
required), e.g.:

        //
        // NOTE: The C# compiler itself needs the backslashes escaped
        //       as well, hence there are 8.
        //
        string fileName = "\\\\\\\\server\\share\\path\\to\\database.db";

--
Joe Mistachkin

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Unable to open database file

Steve Rogers
On 9/23/2014 10:57 PM, Joe Mistachkin wrote:

> Steve Rogers wrote:
>> Reading in order, it says that:
>> SQLiteDb.LDb3.PrepareCommand threw an exception with the message
>> 'unable to open database file'
>>
> Is the database file name a UNC path?  If so, the number of leading
> backslashes must be doubled (i.e. four leading backslashes are now
> required), e.g.:
>
> //
> // NOTE: The C# compiler itself needs the backslashes escaped
> //       as well, hence there are 8.
> //
> string fileName = "\\\\\\\\server\\share\\path\\to\\database.db";
>
> --

In my test today, the path was C:\Users\Public because I was installing
on the machine that will be the machine to hold the database file.

I'll need to take these comments into account when I get to a fully
qualified UNC name on the other computers.

I haven't tested that scenario yet, but I will do soon.

But the problem remains that the failure I describe in my message was
when the database file was on the same machine.

I'm hoping that when I get the problem resolved that when the user uses a
file picker to pick the file, that the path I get back from the file picker
will be properly "decorated" with all the necessary slashes.  If not I can
handle that problem.


>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2014.0.4765 / Virus Database: 4025/8264 - Release Date: 09/23/14
>
>

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Unable to open database file

jose isaias cabrera
"Steve Rogers" wrote...


> On 9/23/2014 10:57 PM, Joe Mistachkin wrote:
>> Steve Rogers wrote:
>>> Reading in order, it says that:
>>> SQLiteDb.LDb3.PrepareCommand threw an exception with the message
>>> 'unable to open database file'
>>>
>> Is the database file name a UNC path?  If so, the number of leading
>> backslashes must be doubled (i.e. four leading backslashes are now
>> required), e.g.:
>>
>> //
>> // NOTE: The C# compiler itself needs the backslashes escaped
>> //       as well, hence there are 8.
>> //
>> string fileName = "\\\\\\\\server\\share\\path\\to\\database.db";
>>
>> --
>
> In my test today, the path was C:\Users\Public because I was installing
> on the machine that will be the machine to hold the database file.
>
> I'll need to take these comments into account when I get to a fully
> qualified UNC name on the other computers.

I have found out that using UNC paths vs a mapped drive to a server, is much
slower.  Specially if you are going to use a database shared amoungst other
folks.  I would suggest a test on both scenario (UNC path and mapped drive)
and place some times on the same calls and you'll see the differences.
Heck, you can see the difference by copying a file.  Ihth.

josé

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Unable to open database file

Keith Medcalf

>I have found out that using UNC paths vs a mapped drive to a server, is
>much slower.  Specially if you are going to use a database shared amoungst
>other folks.  I would suggest a test on both scenario (UNC path and mapped
>drive) and place some times on the same calls and you'll see the differences.
>Heck, you can see the difference by copying a file.  Ihth.

That is likely because using a UNC path is not persistent.  Try mapping the UNC Path first (same as you would do mapping to a drive letter, just leave out the drive letter) and see if that makes a difference.




_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users