0

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?

Roy Tsabari
  • 2,000
  • 6
  • 26
  • 41

2 Answers2

3

Seems like I've figured out what is going on (it could be useful to other people that will meet this problem):

I've used Process Monitor (from Sysinternals) to find out what is the path that the application is trying to access and find out the it is wrong.

My connection string is pointing to a path with the structure: ..\DB\.

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:\).

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

oh...

Roy Tsabari
  • 2,000
  • 6
  • 26
  • 41
0

Are you even connecting to the database on the client? Your error message seems to suggest you aren't?

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 ]

Of course error messages never lie... :-) but it seems to indicate it's not even finding the database at the location specified on the client machine.

Here's someone else who was getting this message and how they solved it.

Community
  • 1
  • 1
Kevin LaBranche
  • 20,908
  • 5
  • 52
  • 76