4

I use a SQL Server CE database from my application. My program is located on a DVD.

I cannot read data from the database on the DVD, I set SQL connection string mode to read only but it doesn't work (I just want to read data from db)

ERROR:

Opening a database as read-only requires a temp path to be specified. [ Db name = C:\Users\Ali\AppData\Local\Temp\Rar$EX52.280... ]

please help!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
KF2
  • 9,887
  • 8
  • 44
  • 77
  • 1
    And what is the error you are getting? – leppie Jul 02 '12 at 07:33
  • Opening a database as read-only requires a temp path to be specified. [ Db name = C:\Users\Ali\AppData\Local\Temp\Rar$EX52.280\... ] – KF2 Jul 02 '12 at 07:52

1 Answers1

7

In order to open a SQL Server CE database file (SDF) on read-only media, you also need to add two additional parameters to the connection string

  • Mode=Read Only
  • Temp Path=[path]

You could do this as follows:

connectionString = String.Format(@"Data Source = {0}\{1};Mode = Read Only;Temp Path={2}", 
          dataBaseDirectory,
          dataBaseName, 
          System.IO.Path.GetTempPath());        

If you are getting your connection string from App.Config

see https://stackoverflow.com/a/10731515/19624

string connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
connectionString += ";Mode = Read Only;Temp Path=" + System.IO.Path.GetTempPath()); 
Community
  • 1
  • 1
Richard Harrison
  • 19,247
  • 4
  • 40
  • 67