Linq to Sql DatabaseExists
Lets say i have a database in c:\database.mdf what is the difference between using co开发者_C百科ntext.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 ?
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.
精彩评论