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

Solved Invalid database Handle 0 (SQL_Query)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 05-20-2020 , 13:42   Invalid database Handle 0 (SQL_Query)
Reply With Quote #1

Every time my plugin attempts to use the native SQL_Query() it sends a Invalid database Handle 0 (error 4) error to the server, saying it's an invalid database handle. However from what I can see on the docs it looks like it's supposed to?

My code:
Code:
Database gH_Db;

stock void SQL_InitDB() {
	char sError[255];
	if(gH_Db == INVALID_HANDLE) {
		gH_Db = SQL_Connect("betterwarden", true, sError, sizeof(sError));
		
		if(gH_Db == INVALID_HANDLE) {
			PrintToServer("### Could not connect to the database! ##");
			PrintToServer("%s", sError);
		} else {
			SQL_CreateBWTable();
		}
	}
}

stock bool SQL_IsInGang(int client) {
	char sQuery[255];
	char sID[64];
	GetClientAuthId(client, AuthId_Steam2, sID, sizeof(sID));
	
	Format(sQuery, sizeof(sQuery), "SELECT GangID FROM betterwarden_players WHERE STEAMID LIKE '%s'", sID);
	
	DBResultSet SQL = SQL_Query(gH_Db, sQuery);
	if(SQL != null) {
		if(SQL_FetchRow(SQL)) {
			CloseHandle(SQL);
			return true;
		}
	}
	
	return false;
}
SQL_InitDB() is called OnPluginStart.

Anyone see why this is happening?
__________________

Last edited by condolent; 05-22-2020 at 16:25.
condolent is offline
Kellan123
AlliedModders Donor
Join Date: Aug 2012
Old 05-20-2020 , 14:58   Re: Invalid database Handle 0 (SQL_Query)
Reply With Quote #2

PHP Code:
if(gH_Db == INVALID_HANDLE
wheres the
PHP Code:
CloseHandle(gH_Db); 
?

Last edited by Kellan123; 05-20-2020 at 14:58.
Kellan123 is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 05-20-2020 , 15:01   Re: Invalid database Handle 0 (SQL_Query)
Reply With Quote #3

Quote:
Originally Posted by Kellan123 View Post
PHP Code:
if(gH_Db == INVALID_HANDLE
wheres the
PHP Code:
CloseHandle(gH_Db); 
?
I want to use that handle for other methods. Won't be able to use it if I close it?
__________________
condolent is offline
Kellan123
AlliedModders Donor
Join Date: Aug 2012
Old 05-21-2020 , 12:08   Re: Invalid database Handle 0 (SQL_Query)
Reply With Quote #4

Quote:
Originally Posted by condolent View Post
I want to use that handle for other methods. Won't be able to use it if I close it?
Then goodluck with the error, you have to close it...
Kellan123 is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 05-21-2020 , 12:47   Re: Invalid database Handle 0 (SQL_Query)
Reply With Quote #5

Quote:
Originally Posted by Kellan123 View Post
Then goodluck with the error, you have to close it...
Do I have to use SQL_Connect in every method before SQL_Query then??
Or do I just need to close it once in Init_SQL() and then be able to re-use the handle later?
__________________
condolent is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 05-21-2020 , 13:03   Re: Invalid database Handle 0 (SQL_Query)
Reply With Quote #6

It's working just fine with
PHP Code:
SQL_FastQuery(gH_DbsQuery); 
But not with
PHP Code:
DBResultSet SQL SQL_Query(gH_DbsQuery); 
__________________
condolent is offline
Kellan123
AlliedModders Donor
Join Date: Aug 2012
Old 05-22-2020 , 12:29   Re: Invalid database Handle 0 (SQL_Query)
Reply With Quote #7

PHP Code:
stock void SQL_InitDB() {
    
char sError[255];
    if(
gH_Db == INVALID_HANDLE) {
        
gH_Db SQL_Connect("betterwarden"truesErrorsizeof(sError));
        
        if(
gH_Db == INVALID_HANDLE) {
            
PrintToServer("### Could not connect to the database! ##");
            
PrintToServer("%s"sError);
            
CloseHandle(gh_Db); // invalid database :lol:
        
} else {
            
SQL_CreateBWTable();
        }
    } 

Last edited by Kellan123; 05-22-2020 at 12:29.
Kellan123 is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 05-22-2020 , 13:35   Re: Invalid database Handle 0 (SQL_Query)
Reply With Quote #8

Quote:
Originally Posted by Kellan123 View Post
PHP Code:
stock void SQL_InitDB() {
    
char sError[255];
    if(
gH_Db == INVALID_HANDLE) {
        
gH_Db SQL_Connect("betterwarden"truesErrorsizeof(sError));
        
        if(
gH_Db == INVALID_HANDLE) {
            
PrintToServer("### Could not connect to the database! ##");
            
PrintToServer("%s"sError);
            
CloseHandle(gh_Db); // invalid database :lol:
        
} else {
            
SQL_CreateBWTable();
        }
    } 
Where did you get that from? Can't close an invalid handle?
__________________
condolent is offline
Kellan123
AlliedModders Donor
Join Date: Aug 2012
Old 05-22-2020 , 13:52   Re: Invalid database Handle 0 (SQL_Query)
Reply With Quote #9

show SQL_CreateBWTable... dont use the last post...

Last edited by Kellan123; 05-22-2020 at 13:52.
Kellan123 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 19:23.


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