Weird behaviour if I included code after File.Exists
So the EvaluateDbFile function is checking if a db file exists, if I leave it as it is now it evaluates correctly to the existence of the file, if it exists it writes "File Exists" to the console and if it doesn't I get "File Does Not Exist" but if I put in a conditional that says if the file doesn't exist run the CreateDb function it creates the file, but doesn't run the CreateDb function as the Console.Writeline in that doesn't trigger.
11 Replies
you need to modify the CreateDb function to properly create the file and then call the SetupDb function. Here's the updated code:
you call the Close method on the FileStream returned by File.Create to ensure that the file is created immediately. Then, you proceed to call the SetupDb function as expected.
Now, when the file does not exist, the CreateDb function will be called and the file will be created before executing the SetupDb function.
Thanks
np tell me if it works because i am not 100%😅
So I've updated it to this, and it works? If I open the file now it's Updated the DB and the tables exist so the .close fixed one part of the issue but I'm till confused on what's going on with my Console.Writelines not working.
maybe need a conole.readline() idk i'm eating rn hope someone else can help u
Which writeline do you mean?
I've got one in the CreateDB function that isn't writing, and some in the SetupDB function.
Did you step through that with the debugger?
Put a breakpoint in your setup db and see what happens.
I can't see an obvious in code reason, why those prints shouldn't be hit.
I just tried this, they don't trigger but if I open the freshly made file it's still got all teh tables
And if you break at the start of
CreateDb()
?So I switched from having the file state in the if and moved it to a Var, and this is interesting, when I clear the folder and run the debugger the file gets made before it gets to this check, so it's somehow getting made before I get to that point.