none
SQL Compact - can't save new column RRS feed

  • Question

  • I have a simple winforms application. I use SQL Compact DB with Linq. I had an image column which holds a client image.

    I wanted to change the column type to string so it will hold the image path. I've changed the column type to nvarchar(500) and the model accordingly.

    If I don't set the image column, I can save the object to the DB with no problem (by using the generated method "SaveChanges").

    When setting the image field and trying to save on my machine (win.7 Home Premium) everything is working great, When setting the image field and trying to save on the client machine (win. XP professional) I get the following error:

    System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlServerCe.SqlCeException: The path is not valid. Check the directory for the database. [ Path = ..\DB\OpticControlMainDB.sdf ]
       at System.Data.SqlServerCe.SqlCeConnection.ProcessResults(Int32 hr)
       at System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent)
       at System.Data.SqlServerCe.SqlCeConnection.Open()
       at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, 
    
    DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
       --- End of inner exception stack trace ---
       at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
       at System.Data.EntityClient.EntityConnection.Open()
       at System.Data.Objects.ObjectContext.EnsureConnection()
       at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
       at System.Data.Objects.ObjectContext.SaveChanges()
       at OpticControl.CustomerDetailsModel.SaveChanges() in <MY_PATH>\CustomerDetailsModel.cs:line 502
       at OpticControl.CustomerDetailsPresenter.SaveCustomerPersonalDetails(Object sender, EventArgs args) in <MY_PATH>\CustomerDetailsPresenter.cs:line 149

    I've tried to create a new column ("imagePath") and delete the old column - the problem is still exist.

    Any idea?

    • Moved by KJian_ Monday, November 14, 2011 6:44 AM (From:SQL Server Compact)
    Saturday, November 12, 2011 6:35 PM

Answers

  • Sorry for flooding, but it seems like I've figured out what is going on (it could be useful to other people that will meet this problem):

    My connection string is pointing to a path with the structure: ..\DB\<THE DB FILE>.

    When getting the image path from the user I am using a FileDialog. Seems like on XP (not on win.7) this chages the appliction context and when using the connection string it starts to navigate from  the dialog last folder (is the selected picture is located at c:\pics\pic.jpg, the the app will access the DB in the path c:\<THE DB FILE>).

     

    I've validate that this was the issue by using an absolute path (instead of relative).

    oh...

    Tuesday, November 15, 2011 2:51 PM

All replies

  • Hi Royts,

    I'm sorry I have no sql compact on my machine, but based on your exception information, I think there's two reasons may lead to that.

    1. The client machine doesn't install Sql Compact. DownLoad the suitable version of the DB and install it on your client machine.

    2. Your code may compiled with X64 platform, but win XP has no x64 version, so the provider is not suitable to your client machine. You can compile the code again with x86 platform. 

    If you have any problem, please let me know.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, November 15, 2011 4:00 AM
    Moderator
  • Hi Allen,

    Thank you for the replay,

    I've installed the client XP machine the suitable  SQL Compact. I did that on local XP VM, and I see the same problem.

    I've verified the all the projects in my solution are configured with "platform target = x86" (for "All Configurations").

     

    Any idea what is going on?

    Tuesday, November 15, 2011 12:57 PM
  • Hi again, I have more info:

    I've used Process Monitor (from Sysinternals) and find out that when I set the new property and try to save the application is trying to reach a path that is not exist.
    The is weird as the configurations files includes only one connection string with the right path.

     

    Any idea?

     

     

     

    Tuesday, November 15, 2011 2:32 PM
  • Sorry for flooding, but it seems like I've figured out what is going on (it could be useful to other people that will meet this problem):

    My connection string is pointing to a path with the structure: ..\DB\<THE DB FILE>.

    When getting the image path from the user I am using a FileDialog. Seems like on XP (not on win.7) this chages the appliction context and when using the connection string it starts to navigate from  the dialog last folder (is the selected picture is located at c:\pics\pic.jpg, the the app will access the DB in the path c:\<THE DB FILE>).

     

    I've validate that this was the issue by using an absolute path (instead of relative).

    oh...

    Tuesday, November 15, 2011 2:51 PM
  • Hi Royts,

    Sorry for come back late, I'm glad to hear that you got it working and thanks for your sharing. I believe people who encoutered this issue can get useful information from your post.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, November 16, 2011 1:48 AM
    Moderator