The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Neal (1) [Avatar] Offline
#1
Hi

In chapter 1, I am unable to use the Datacontext by pointing the path to the DataNorthwnd.mdf file. The query returns zero result. The connection string seems to be correct. But I get in results in watch window, something as {Instance failure}. I am using VS2008. What am I missing?
Abacus (59) [Avatar] Offline
#2
Re: Problem Using the DataNorthwin.mdf
Hi Neal,

I struggled with the same problem earlier today.

The solution for me was to enter the full path name of the database manually, without using the GetFullPath() function. I found that this function returned the wrong path.

The "@" sign before the string makes sure that backslashes are not interpreted as escape characters.

Let me know if this solves the problem for you too.

Cheers,

Abacus (pseudonym)
fabrice.marguerie (224) [Avatar] Offline
#3
Re: Problem Using the DataNorthwin.mdf
Thanks for your help Abacus.

I'm curious about this issue. What does GetFullPath() return in your case and what is the correct path?
Of course it works fine on my computers.
Maybe you put the files under "My Documents"? This is a source of problems in many cases. I usually advise not to put anything under this special folder.

Fabrice
Abacus (59) [Avatar] Offline
#4
Re: Problem Using the DataNorthwin.mdf
Hi Fabrice,

Thank you for your prompt comment on my post.

This is what the GetFullPath() function returned:

Csmilierogram FilesMicrosoft Visual Studio 9.0Common7IDEApp_Codedatabase.mdf.

The correct path was something like this:

Csmilieocuments and SettingsPaulMyDocumentsVisualStudio2008WebSites
LinqSite4App_Codedatabase.mdf

(with no line break).

Why does putting the files under My Documents cause problems?

Thank you for your trouble.

Abacus
fabrice.marguerie (224) [Avatar] Offline
#5
Re: Problem Using the DataNorthwin.mdf
I'm not surprised that "My Documents" is not handled properly by APIs like GetFullPath(). It's not the first time that I've seen problems with this folder. You may also encounter security issues, problems with the debugger, and so on. You should really put your documents elsewhere if you don't want troubles.

Note: I see that your database is in App_Code. This is surprising. It should be in App_Data, shouldn't it?
Abacus (59) [Avatar] Offline
#6
Re: Problem Using the DataNorthwin.mdf
Hi Fabrice,

Thank you for catching my mistake of putting the database file in the wrong folder.

Do you have any idea why GetFullPath() and other APIs have trouble with "My Documents"?

Cheers,

Abacus