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!

2
  • 1
    And what is the error you are getting? Commented Jul 2, 2012 at 7: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\... ] Commented Jul 2, 2012 at 7:52

1 Answer 1

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()); 
Sign up to request clarification or add additional context in comments.

1 Comment

i get my connection string from app.config.how do change it programmatically?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.