alvyxaz / barebones-masterserver

Master Server framework for Unity
475 stars 106 forks source link

Postgresql DB Factory 'successfully' connects to DB even if no DB exists #198

Open Fullmight opened 6 years ago

Fullmight commented 6 years ago

Pretty much right in the title, despite the try catch, the OnServerStarted function will never throw an error regardless of what nonsense you put in the connection string. This makes it pretty hard to tell when you're failing to connect.

ghost commented 6 years ago

I didn't encounter this problem, since I had already set up the database when I started using the scripts. Haven't checked npgsql's source code (which I think you can find at their site).

From what I see, checking through the scripts for npgsql, it seems that that AuthDbPostgreSQL and ProfilesDbPostgreSQL classes do not throw any exception in their constructors. In fact, their constructors don't use any function from NpgsqlConnection and simply just pass a string. To fix this, you can simply make two new classes that inherit from the two above and make new constructors, where you try to connect yourself to the database once and close the connection. If it fails to connect, just throw the exception.

I'm pretty sure that NpgsqlConnection does throw an exception somewhere, be it in its constructor or its Open() method. Better use both in your constructors. If it still throws no exception that way, well, I'm sorry, that's all I could think of in the limited time I have. Good luck!