5

I have Database (compact sql server) in a *.sdf file. I converted a compact framework project to a regular pc project and for some reason, with the same code, and the same *.sdf file the following exception was thrown: "the file name is not valid. check the file name for the database"

the weird thing is that on my Pc - the substring "file:\" was added to my original connection string and that's probably why the exception is thrown. when I remove the "file:\" substring during debug mode, on runtime, the exception is not thrown.

why was this substring added? where does it come from? and how can I solve this problem?

recently I discovered that there may some some connection to the fact that the app.config file is missing. This still doesn't explain how the original connection string exists, only with it's added substring.

Please help. thanks in advance

2
  • Is the sdf file local? In a subfolder? Where is it? Can you give an example of what your connection string looks like? Commented Sep 13, 2010 at 12:56
  • Yes, it is local. It is located in "C:\solutionname\projectname\bin\debug\sdfname.sdf" the connection string: "file:\\C:\\solutionname\\projectname\\bin\\debug\\sdfname.sdf" Commented Sep 13, 2010 at 13:19

2 Answers 2

1

I don't see why you would need "file://". It should work without that just fine. For sure it looks wrong that you have file:\ instead of file://

Sign up to request clarification or add additional context in comments.

2 Comments

maybe I didn't explain myself correctly.. the "file:\" prefix was added automatically by itself - I didn't add it. That is why the exception is thrown (not by me, by the framework). I have no idea why that happens. I'd wish to find the origin of that prefix and understand why that happens, but right now I would even saddle for removing it directly in runtime before I call the function that throws the exception. Unfortunately the connection string is private and due to that - I got no access to it.
You did make it clear, I just didn't read it properly. Your connection string should be: "Data Source=c:\db.sdf".
0

Since windows CE does not have a "current directory", implementations usually get the location of the currently running assembly as a directory to look in. On a desktop, the string returned by Assembly.GetExecutingAssembly().GetName().CodeBase includes that scheme prefix.

3 Comments

what is the Assembly.GetexecutingAssembly().GetName().CodeBase? and how do I fix that problem?
If you enter "sdfname.sdf", then the process opening that file will have to resolve it to, for instance, "c:\somefolder\sdfname.sdf". On windows machines developers usually assume the file is in the current folder, but as Windows CE deviced don't have a "current folder", CE developers usually use the path of the Assembly.
On Windows CE this function returns a path you can use unmodified to open a file, while on the full framework a scheme prefix (file:\\) is added. I don't know where this conversion from relative to absolute happens, if it's in a 3rd party library you could see if they have a full framework version you can use instead of the CF version?

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.