Raised This Month: $51 Target: $400
 12% 

Exception reported: Invalid database Handle 0 (error: 4)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SirFulgeruL
Junior Member
Join Date: Jun 2015
Old 08-26-2017 , 17:39   Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #1

Hello guys , so I have a plugin that displays in chat a tag for admins and the plugin is fully working but whenever this error comes in the console the server will have a freeze for 1 second and it's a bit annoying. A friend that has a hosted server isn't having any issues with the plugin , but me because I have a dedicated server and propably some libraries or something like that are missing I recieve this error .
Code:
L 08/26/2017 - 23:21:28: [SM] Exception reported: Invalid database Handle 0 (error: 4)
L 08/26/2017 - 23:21:28: [SM] Blaming: acct.smx
L 08/26/2017 - 23:21:28: [SM] Call stack trace:
L 08/26/2017 - 23:21:28: [SM]   [0] SQL_TQuery
L 08/26/2017 - 23:21:28: [SM]   [1] Line 432, acct.sp::Timer_Reload

sm exts list output:

Code:
[SM] Displaying 17 extensions:
[01] Automatic Updater (1.9.0.6080): Updates SourceMod gamedata files
[02] Webternet (1.9.0.6080): Extension for interacting with URLs
[03] <FAILED> file "cmdfix.ext.2.csgo.so": File could not be opened: No such file or directory
[04] CS Tools (1.9.0.6080): CS extended functionality
[05] BinTools (1.9.0.6080): Low-level C/C++ Calling API
[06] SDK Tools (1.9.0.6080): Source SDK Tools
[07] SDK Hooks (1.9.0.6080): Source SDK Hooks
[08] Top Menus (1.9.0.6080): Creates sorted nested menus
[09] Client Preferences (1.9.0.6080): Saves client preference settings
[10] SQLite (1.9.0.6080): SQLite Driver
[11] Regex (1.9.0.6080): Provides regex natives for plugins
[12] DHooks (2.0.6): Dynamic Hooks
[13] GeoIP (1.9.0.6080): Geographical IP information
[14] <FAILED> file "store_sm.ext.so": /home/arena/csgo/addons/sourcemod/extensions/store_sm.ext.so: cannot open shared object file: No such file or directory
[15] SteamWorks Extension (1.2.2): Exposes SteamWorks functions to Developers
[16] <FAILED> file "PTaH.ext.2.csgo.so": Could not read PTaH.games: File could not be opened: No such file or directory
[17] MySQL-DBI (1.9.0.6080): MySQL driver implementation for DBI
ldd -d dbi.mysql.ext.so output:

Code:
        linux-gate.so.1 (0xf77ca000)
        libm.so.6 => /lib/i386-linux-gnu/i686/cmov/libm.so.6 (0xf75d0000)
        libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xf75b3000)
        libpthread.so.0 => /lib/i386-linux-gnu/i686/cmov/libpthread.so.0 (0xf7596000)
        librt.so.1 => /lib/i386-linux-gnu/i686/cmov/librt.so.1 (0xf758d000)
        libc.so.6 => /lib/i386-linux-gnu/i686/cmov/libc.so.6 (0xf73e0000)
        /lib/ld-linux.so.2 (0x565de000)
SirFulgeruL is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 08-26-2017 , 17:59   Re: Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #2

That error has nothing to do with extension load failures (as you would get error that no MYSQL or SQLITE driver was located), the error is associated with trying to use an invalid handle for DB operations
__________________

Last edited by WildCard65; 08-26-2017 at 18:00.
WildCard65 is offline
SirFulgeruL
Junior Member
Join Date: Jun 2015
Old 08-26-2017 , 18:02   Re: Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #3

And what can I do in this situation?
I have the source of the plugin and I could recompile it , if you could help me out
SirFulgeruL is offline
SirFulgeruL
Junior Member
Join Date: Jun 2015
Old 08-27-2017 , 06:03   Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #4

Hello guys , so I have a plugin that displays in chat a tag for admins and the plugin is fully working but whenever this error comes in the console the server will have a freeze for 1 second and it's a bit annoying. A friend that has a hosted server isn't having any issues with the plugin , but me because I have a dedicated server and propably some libraries or something like that are missing I recieve this error .

Code:
L 08/26/2017 - 23:21:28: [SM] Exception reported: Invalid database Handle 0 (error: 4)
L 08/26/2017 - 23:21:28: [SM] Blaming: acct.smx
L 08/26/2017 - 23:21:28: [SM] Call stack trace:
L 08/26/2017 - 23:21:28: [SM]   [0] SQL_TQuery
L 08/26/2017 - 23:21:28: [SM]   [1] Line 432, acct.sp::Timer_Reload
Here is the whole if including the line error:
Code:
	public Action Timer_Reload(Handle pTimer, any _Data)
{
	static int iId = INVALID_ENT_REFERENCE;
	static char szError[PLATFORM_MAX_PATH] = "";
	static char szSteam[PLATFORM_MAX_PATH] = "";

	if (g_pDb == INVALID_HANDLE)
	{
		g_pDb = SQL_Connect("main_db", false, szError, sizeof(szError));
		
		if (g_pDb != INVALID_HANDLE)
		{
			SQL_SetCharset(g_pDb, "utf8");
		}
	}
	
	FormatEx(g_Buffer, sizeof(g_Buffer), "DELETE FROM sm_tags WHERE Stamp < %d;", GetTime() - (86400 * 7 * 3));
	
	SQL_TQuery(g_pDb, Q_Empty, g_Buffer, _, DBPrio_High);
	SQL_TQuery(g_pDb, Q_SelectData, "SELECT Steam, Tag, colorCode FROM sm_tags;", _, DBPrio_High);
	
	for (iId = 1; iId <= MaxClients; iId++)
	{
		if (IsClientInGame(iId))
		{
			GetClientAuthId(iId, AuthId_Engine, szSteam, sizeof(szSteam));
			
			hCSGO_ExtractSteamID(szSteam, szSteam, sizeof(szSteam));
			
			FormatEx(g_Buffer, sizeof(g_Buffer), "UPDATE sm_tags SET Stamp = %d WHERE Steam = '%s' LIMIT 1;", GetTime(), szSteam);
			SQL_TQuery(g_pDb, Q_Empty, g_Buffer, _, DBPrio_Low);
			FormatEx(g_Buffer, sizeof(g_Buffer), "UPDATE sm_music SET Stamp = %d WHERE Steam = '%s' LIMIT 1;", GetTime(), szSteam);
			SQL_TQuery(g_pDb, Q_Empty, g_Buffer, _, DBPrio_Low);
		}
	}
}

Last edited by SirFulgeruL; 08-27-2017 at 07:42.
SirFulgeruL is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 08-27-2017 , 06:35   Re: Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #5

The error is about the SQL_TQuery native which you don't call at all in the code you pasted. Recheck you're looking at the right file and line!
__________________
Peace-Maker is offline
SirFulgeruL
Junior Member
Join Date: Jun 2015
Old 08-27-2017 , 07:28   Re: Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #6

I didn't made the plugin , I got it from a friend .
Here are all the lines from the script that includes SQL_TQuery
Code:
public Action Timer_Reload(Handle pTimer, any _Data)
{
	static int iId = INVALID_ENT_REFERENCE;
	static char szError[PLATFORM_MAX_PATH] = "";
	static char szSteam[PLATFORM_MAX_PATH] = "";

	if (g_pDb == INVALID_HANDLE)
	{
		g_pDb = SQL_Connect("main_db", false, szError, sizeof(szError));
		
		if (g_pDb != INVALID_HANDLE)
		{
			SQL_SetCharset(g_pDb, "utf8");
		}
	}
	
	FormatEx(g_Buffer, sizeof(g_Buffer), "DELETE FROM sm_tags WHERE Stamp < %d;", GetTime() - (86400 * 7 * 3));
	
	SQL_TQuery(g_pDb, Q_Empty, g_Buffer, _, DBPrio_High);
	SQL_TQuery(g_pDb, Q_SelectData, "SELECT Steam, Tag, colorCode FROM sm_tags;", _, DBPrio_High);
	
	for (iId = 1; iId <= MaxClients; iId++)
	{
		if (IsClientInGame(iId))
		{
			GetClientAuthId(iId, AuthId_Engine, szSteam, sizeof(szSteam));
			
			hCSGO_ExtractSteamID(szSteam, szSteam, sizeof(szSteam));
			
			FormatEx(g_Buffer, sizeof(g_Buffer), "UPDATE sm_tags SET Stamp = %d WHERE Steam = '%s' LIMIT 1;", GetTime(), szSteam);
			SQL_TQuery(g_pDb, Q_Empty, g_Buffer, _, DBPrio_Low);
			FormatEx(g_Buffer, sizeof(g_Buffer), "UPDATE sm_music SET Stamp = %d WHERE Steam = '%s' LIMIT 1;", GetTime(), szSteam);
			SQL_TQuery(g_pDb, Q_Empty, g_Buffer, _, DBPrio_Low);
		}
	}
}
SirFulgeruL is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 08-27-2017 , 08:08   Re: Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #7

You are using SQL_Connect, which is non-threaded, causing your server to freeze for 1 second (use SQL_TConnect instead). Subsequently you are not checking if there is an error in szError, so SQL_TQuery fails because g_pDb is still INVALID_HANDLE.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 08-27-2017 at 08:10.
DJ Tsunami is offline
SirFulgeruL
Junior Member
Join Date: Jun 2015
Old 08-27-2017 , 08:10   Re: Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #8

Sadly , I don't have any coding knowledge and I don't know how to repair it .
If someone could help me I would be grateful .
SirFulgeruL is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 08-27-2017 , 08:12   Re: Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #9

I see your problem, you never bail out (and report error) upon connection failure.

PHP Code:
    if (g_pDb == INVALID_HANDLE)
    {
        
g_pDb SQL_Connect("main_db"falseszErrorsizeof(szError));
        
        if (
g_pDb != INVALID_HANDLE)
        {
            
SQL_SetCharset(g_pDb"utf8");
        }
    } 
change it to:


PHP Code:
    if (g_pDb == INVALID_HANDLE)
    {
        
g_pDb SQL_Connect("main_db"falseszErrorsizeof(szError));
        if (
g_pDb == INVALID_HANDLE)
        {
            
ThrowError("Connection to database (as specified by \"main_db\") failed, error: %s"szError);
            return 
Plugin_Stop// Satisfy the compiler
        
}

        
SQL_SetCharset(g_pDb"utf8");
    } 
Edit: As DJ Tsunami mentions, use the threaded connection.
__________________

Last edited by WildCard65; 08-27-2017 at 08:13.
WildCard65 is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 08-27-2017 , 08:17   Re: Exception reported: Invalid database Handle 0 (error: 4)
Reply With Quote #10

If you want someone to fix it for you, you need to post the whole plugin. Or if your friend is the one who wrote it, ask them.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 08-27-2017 at 08:21.
DJ Tsunami is offline
Reply



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 09:21.


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