开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜