How to open a SQL Compact read-only database

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

I noticed that if I use adodbapi, the database file actually changes only by opening it. And unfortunately, when I add "File mode = Read Only" to the connection string, I get a strange 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 an error

 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 SSCE because when I wrote a test program in C #, it needed it. The following code works fine and does not modify the file when you execute 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
python sql-server-ce ado
source share

All Articles