locked
Using EF with a temp file RRS feed

  • Question

  • Hello,

    I'm working with an EF data model with SQL CE (i.e. using Entity.Infrastructure.SqlCeConnectionFactory) and would like the ability to store it to a temporary file until the user actually chooses to save. But when I try to pass a temp file name in the connection string (retrieved from System.Io.Path.GetTempFileName()) it looks like the initialization of the database doesn't complete unless the file ends with .sdf. I've also tried creating a DbConnection object directly with the same results. If this is the case I can live with it, I would just like to know if there's some obscure setting that changes this or something else I'm missing.

    Thanks

    Monday, June 18, 2012 4:04 PM

Answers

  • Yes, the file name must be ended with '.sdf'. If you get the name by System.Io.Path.GetTempFileName(), you can concatenate the name with '.sdf' before pass it to the connection string.
    • Marked as answer by Atlantisbase Wednesday, June 20, 2012 3:57 PM
    Wednesday, June 20, 2012 9:31 AM

All replies

  • Hi Atlantisbase,

    Welcome to MSDN Forum.

    I'm not clear about the meaning of 'store it to a temporary file'. Could you please clarify what you want to store and what's the purpose of it?

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 19, 2012 5:40 AM
  • Meaning the database file starts as a temp (.tmp) file in the users Temp folder, then if they choose to save, I copy it to the chosen location. I'd like to do it this way to keep it relatively transparent to the user. Unless there's a way to keep an EF context in memory, that is not have a database file on disk at all?
    Tuesday, June 19, 2012 3:14 PM
  • Hi Atlantisbase,

    Keeping an ObjectContext a long time isn't a good practice. Commonly, we often instantiate an ObjectContext in a using statement, so that we can make sure it will be closed after a unit operation completing.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 20, 2012 5:00 AM
  • Yes, I know that. I'm simply interested in using a file in the TEMP directory until the user saves. The main issue is that the sql ce file won't be created unless the path is a .sdf.
    Wednesday, June 20, 2012 5:46 AM
  • Yes, the file name must be ended with '.sdf'. If you get the name by System.Io.Path.GetTempFileName(), you can concatenate the name with '.sdf' before pass it to the connection string.
    • Marked as answer by Atlantisbase Wednesday, June 20, 2012 3:57 PM
    Wednesday, June 20, 2012 9:31 AM
  • Ok, that's what I'm doing now. It's just a little less opaque to the user if they go poking around in their Temp folder.
    Wednesday, June 20, 2012 4:00 PM