Raised This Month: $535 Target: $400
 133% 

Database.Connect callback is not invoked until i unload plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gromit190
Junior Member
Join Date: Jun 2019
Old 11-24-2022 , 16:00   Database.Connect callback is not invoked until i unload plugin?
Reply With Quote #1

Hello,

I am following the example from the docs:

Code:
Database hDatabase = null;
 
void StartSQL()
{
    Database.Connect(GotDatabase);
}
 
public void GotDatabase(Database db, const char[] error, any data)
{
    PrintToServer("Got database2"); // <--- this won't actually happen until I do: sm plugins unload myplugin
    if (db == null)
    {
        LogError("Database failure: %s", error);
    } 
    else 
    {
        hDatabase = db;
    }
}
But, for some odd reason, the "GotDatabase" is not invoked unless I unload the plugin.

In the GotDatabase function I am calling "PrintToServer", and also I am inserting a row to the db. I monitor both the server console, and the table in the db and nothing happens UNLESS I unload the plugin.

What am I doing wrong?

Last edited by gromit190; 11-24-2022 at 16:00.
gromit190 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-24-2022 , 17:42   Re: Database.Connect callback is not invoked until i unload plugin?
Reply With Quote #2

Close connection by deleting Handle.
Code:
delete hDatabase ;
__________________
Do not Private Message @me
Bacardi is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-25-2022 , 15:50   Re: Database.Connect callback is not invoked until i unload plugin?
Reply With Quote #3

This sounds like there is something wrong with the DB thread on your server.

When you unload the plugin SM shifts all the pending threaded operations to happen on the main game thread in order to block the plugin unloading until they're complete.
__________________
asherkin is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:33.


Powered by vBulletin®
Copyright ©2000 - 2023, vBulletin Solutions, Inc.
Theme made by Freecode