Raised This Month: $ Target: $400
 0% 

SQL_PrepareQuery Run Time Error 10


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Russianeer
SourceMod Donor
Join Date: Feb 2011
Old 04-23-2011 , 17:36   SQL_PrepareQuery Run Time Error 10
Reply With Quote #1

Error:
Code:
L 04/23/2011 - 09:35:36: [MySQL] Invalid database handle: 0
L 04/23/2011 - 09:35:36: [AMXX] Displaying debug trace (plugin "aps_autosave.amxx")
L 04/23/2011 - 09:35:36: [AMXX] Run time error 10: native error (native "SQL_PrepareQuery")
L 04/23/2011 - 09:35:36: [AMXX]    [0] aps_autosave.sma::client_connect (line 170)
Code:
PHP Code:
public client_connect(id)
{
    
// Check for steam ID pending
    
static steamid[32];
    
get_user_authid(idsteamid31);
    
    
// Then the player doesn't have a steam id, lets make them reconnect
    
if ( equal(steamid"STEAM_ID_PENDING") )
    {
        
client_cmdid"reconnect" );
        
        return 
PLUGIN_HANDLED;
    }

    
g_saps[id] = 0;
    
loaded[id] = 0
    
    
new szQuery[256];

    
format(szQuery255"SELECT * FROM cs_bank WHERE steamid = '%s'"steamid);

    new 
Handle:query SQL_PrepareQueryg_DBConnszQuery );

    if( !
SQL_Executequery ) )
    {
        
server_print("[APS] Connection to the database failed.")

        return 
PLUGIN_HANDLED;
    }
        
    if(
SQL_NumResultsquery ) != 0)
    {
        
LoadUser(id);
        
SQL_FreeHandle(query);
        return 
PLUGIN_HANDLED
    
}
    
    if(
SQL_NumResults(query) == 0)
    {
        
SQL_FreeHandle(query);

        
format(szQuery255"INSERT INTO `cs_bank` (`steamid`, `aps`, `saps`) VALUES ('%s', '0', '0')"steamid);
            
zp_set_user_ammo_packs(id10);
            
g_saps[id] = 5;

        
query SQL_PrepareQuery(g_DBConnszQuery);

        if(!
SQL_Execute(query))
        {
            
server_print("[APS] Database Error at creating an ammo pack field.");
            return 
PLUGIN_HANDLED;
        }

        
SQL_FreeHandle(query);
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_HANDLED;

Line 170:
PHP Code:
new Handle:query SQL_PrepareQueryg_DBConnszQuery ); 
Task I am trying to achieve here is to load certain fields from the database. And I do achieve it, but for some reason, get this error from time to time. And I believe it happens when the query doesn't load anything from the query to the variables.

Does anyone know what could this be?
Russianeer is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-24-2011 , 13:49   Re: SQL_PrepareQuery Run Time Error 10
Reply With Quote #2

It means that your g_DBConn is an invalid handle.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Russianeer
SourceMod Donor
Join Date: Feb 2011
Old 04-24-2011 , 15:16   Re: SQL_PrepareQuery Run Time Error 10
Reply With Quote #3

Quote:
Originally Posted by Exolent[jNr] View Post
It means that your g_DBConn is an invalid handle.
Well most of the clients that join get their infos loaded from the database just fine. It's sometimes that this happens. Does that mean that it's dropping connections?
Russianeer is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-24-2011 , 22:06   Re: SQL_PrepareQuery Run Time Error 10
Reply With Quote #4

Where do you create the connection (what function)?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Russianeer
SourceMod Donor
Join Date: Feb 2011
Old 04-24-2011 , 22:52   Re: SQL_PrepareQuery Run Time Error 10
Reply With Quote #5

I set a timer on plugin_init, to connect to the SQL database after 1 second.

This is the connection:
PHP Code:
public MYSQLX_Init()
{
    new 
sqlhostname[35],sqluser[35],sqlpass[35],sqldbname[35];
    
    
get_cvar_string("zp_sql_host"sqlhostname,34);
    
get_cvar_string("zp_sql_user"sqluser,34);
    
get_cvar_string("zp_sql_pass"sqlpass,34);
    
get_cvar_string("zp_sql_db"sqldbname,34);

    
// Determine the database information
    
new szError[256], iErrNum;

    
// Set up the tuple that will be used for threading
    
g_DBTuple SQL_MakeDbTuple(sqlhostnamesqlusersqlpasssqldbname );

    
// Attempt to connect
    
g_DBConn SQL_Connect(g_DBTupleiErrNumszError255);

    if (!
g_DBConn)
    {
        
log_to_file("ZP-Bank.log""[ZP-APS] Database Connection Failed: [%d] %s"iErrNumszError);

        return;
    }

    
DBConnection true;
    
server_print("[ZP-APS] MySQL database connection successful");

Russianeer is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-25-2011 , 02:06   Re: SQL_PrepareQuery Run Time Error 10
Reply With Quote #6

Players can connect during that time, calling the client_connect() forward before your connection to the database is made.
That is why you are getting your error.

Instead of setting a task, you can create a separate config file with the cvars and force it to execute it on plugin_init() then read the cvars values for the connection.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
xernobil
New Member
Join Date: Jun 2011
Old 07-07-2011 , 00:10   Re: SQL_PrepareQuery Run Time Error 10
Reply With Quote #7

Sorry for my bad English

Exolent, friend can you help me not quite understand I have the same problem, what should I do? help me

tkx
xernobil 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:46.


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