How to open SQL Compact database read only

There is a SQL Compact v3.1 database that I want to quickly read. I'm doing this in python so I don't have access to managed code.

I've noticed that if I use adodbapi the database file actually gets modified just by opening it. And sadly when I add 'File mode=Read Only' to the connection string I get a weird error.

Here is the code I use to connect:

import adodbapi
adodbapi.connect('Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0; Data Source="awesome.sdf"; File mode = Read Only;SSCE:Temp File Directory=c:\temp\\;')

And then I get the error message

OperationalError: (com_error(-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Service Components', 
             u'Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.', 
             None, 0, -2147217887), None), 
    u'Error opening connection: Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0; Data Source="Awesome.sdf";File mode = Read Only;SSCE:Temp File Directory="c:\\\temp\\";')

I added the SSCE because when I wrote a test program in C# it needed it. The following code works perfectly fine and doesn't modify the file when you do a simple SELECT query.

conn = new SqlCeConnection("Data Source = awesome.spf; File mode = Read Only;SSCE:Temp File Directory=\"c:\\users\\evelio\\desktop\\\";");
conn.Open();

Thanks for the help,
Evelio

6
задан evelio 24 September 2010 в 18:57
поделиться