Probing DB for exisistance while using Fb Embedded

19 views
Skip to first unread message

Lars Weber

unread,
Apr 9, 2021, 2:05:10 AM4/9/21
to firebird-net-provider
Hello everyone,

while working on a application that uses fb embedded, i accidently had a different connection to my db file open and thus fbclient was uanable to lock the db file exclusively for its own purposes. While thats totally fine and obviously a mistake by me, the method that checks wether the db file exists or not actually told ef core that the db file does not exist, which is not true. In the .NET-Provider implementation, there is a method Exists() that will try to open a connection and returns false, if an exception is thrown. I would expect that method to retrun true, if the actual database file exists, but just can not be connected to. Maybe because a different client is connected excluvely on that db. 
For my particular case i am now looking explicitly for the excpetion with that error code and probing the db file itself via File.Exists(), but that will certainly not work via network, so i am not sure what, or if we can do something about that on the Provider level. my feelings are, that there might have to be a additional error code returned by fbclient indicating that the db itself exists, but cant be accessed at the moment instead of using the "CreateFile (open)" exception for both cases.
A screenshot of me stepping though the Exists() method is attached, maybe this is helpful.

Regards,
Lars Weber
2021-04-08 15_43_38-.png

Jiří Činčura

unread,
Apr 9, 2021, 3:33:56 AM4/9/21
to 'Mr. John' via firebird-net-provider
This is really poor mans exists, because Firebird does not have any "master" database or anything like that. And even checking whether the file exists on the disk is not a great solution. The file might exist, but might not be valid Firebird database. Similarly for network calls the call might fail because network is not available.

It's never going to be perfect, even with "master" database - the database might be dropped right after the test succeeds.

That said, I'm not saying contributions into the implementation are not welcome. You're welcome to explore some better implementations.

--
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

Reply all
Reply to author
Forward
0 new messages