Reputation: 101150
How do I check if a database exist in esent?
I can use Api.JetAttachDatabase
and Api.JetOpenDatabase
to open an existing database and use Api.JetCreateDatabase
to create a new one. But I can't find an API that allows me to check whether a DB exists.
Do I really have to catch an exception from Api.JetAttachDatabase
to detect if the db exist?
Upvotes: 0
Views: 537
Reputation: 471
I'll apologize for the lack of details because I'm on vacation and don't have the source code handy. :) This is off the top of my head.
o Api.JetAttachDatabase calls JetApi.JetAttachDatabase.
o JetApi.JetAttachDatabase returns an error code (which is what you want!).
o Api.JetAttachDatabase converts that to an exception.
The biggest problem may be that JetApi.Xxx may not be public. It may be internal-only. I'd have to ask the original author if there's a reason for it not be public. If there isn't one, I can make the change in a future release of ManagedEsent.
Sorry for the uncertain answer.
Hey, I was just wondering: what about a CLR function, like File.Exists() ?
-martin
Upvotes: 1
Reputation: 154
You shouldn't have to catch the exception, the return type returns an JET_ERR type that will let you know if there is a problem, if you are looking for a simple bool check, I believe you may be out of luck, or have to write your own.
Source :
http://msdn.microsoft.com/en-us/library/gg294074.aspx
http://msdn.microsoft.com/en-us/library/gg294092.aspx
const JET_errSuccess = 0;
result = JetCreateDatabase(...);
if(result != JET_errSuccess)
{
//throw error
}
Upvotes: 0