Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 215
evelio Avatar asked Sep 24 '10 18:09

evelio


1 Answers

Look here: http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/bf70c615-b279-4a91-b964-0ff99adc7ab8/#674f6a79-a3b4-4601-a952-860a7e8f3169 cn.Mode = adModeRead

like image 87
ErikEJ Avatar answered Nov 09 '22 02:11

ErikEJ