tags:

views:

20

answers:

1

Hi....

Lets say i have a database in c:\database.mdf what is the difference between using context.DatabaseExists("c:\database.mdf") or just simply checking with File.exists("c:\database.mdf") ?

i ask this because i get strange behavior form DatabaseExists method : it tells me sometimes that c:\database.mdf exists but it's not there, because i manually deleted the file from windows explorer.

what am i missing ?

+1  A: 

DatabaseExists actually tries to open a connection to the database. This means it must be a valid database.

FileExists only checks whether a file with that name exists, not whether it is valid.

You could create a .txt file and rename it database.mdf. FileExists will return true while DatabaseExists will return false.

jwsample
ok, i understand, but in my case, i deleted my file manuallyand CreateDatabase method throws an exception which says the database name already exists.
Yaron Levi
Is it possible you just removed it from your project instead of deleting it?
jwsample