Monday, September 20, 2010

WP7 Deploy Db as Content File

Some readers asked me about the possibility to use a database file deployed as Content with the project. Using the file directly from the content folder it is not possible as we do not have read/write access to content files. In fact if we use only the silverlight assemblies we don't have access to any content file. The solution is to use TitleContainer.Openstream from Microsoft.Xna.Framework (a reference should be added manually to your project) to read the content file and then save it to the IsolatedStorage. Once we have the file on IsolatedStorage we can use SQLiteClient to access it.

I've published an updated version of the SQLiteClient project adding a content file (test.db) and there is also ExecuteScalar inside the SQLiteCommand class.



6 comments:

  1. You don't need to use the TitleContainer for this. You can use Application.GetResourceStream in SL projects to read from XAP content.

    ReplyDelete
  2. Beautiful, thanks again. Oh and I went with Application.GetResourceStream() and it worked great.

    ReplyDelete
  3. It's better Application.GetResourceStream because ytou don't have to add reference to XNA assembly

    ReplyDelete
  4. @ Mugunth Kumar : Did you found a solution for this problem? I getting the same error.

    Thanks

    ReplyDelete
  5. Help, I opened the sample project and my debug button is greyed out... If i hit f5 to debug nothing happens.... Any clues???

    ReplyDelete
  6. Hi,

    Its cool lib, thanks, but is there a way to get this file from simulator/device to check if data is properly inserted. I would really appreciate any help.

    Thanks

    ReplyDelete