Bonsai Posted May 25, 2016 Share Posted May 25, 2016 Hey Peeps, I'm having a little problem with my Mysql Database connection. If the server just started, it works fine. But if I restart my database resource, it won't connect anymore. I'm also using destroyElement on the connection in the onResourceStop event of that resource. Does anyone know what the problem is? Bonsai Link to comment
xXMADEXx Posted May 26, 2016 Share Posted May 26, 2016 Could you post the code, please? Link to comment
Bonsai Posted May 26, 2016 Author Share Posted May 26, 2016 function Database.main() Database.connection = dbConnect("mysql", "dbname=**;host=**" ,"**", "**") if not Database.connection then Database.connection = dbConnect("mysql", "dbname=**;host=**" ,"**", "**") if not Database.connection then outputDebugString("Database Connection failed!") end else outputDebugString("Database Connection successful!") end end addEventHandler("onResourceStart", resourceRoot, Database.main) function Database.kill() if isElement(Database.connection) then destroyElement(Database.connection) end outputDebugString("Database Connection killed!") end addEventHandler("onResourceStop", resourceRoot, Database.kill) function getConnection() return Database.connection end Thats all. The last function is exported to be used by other resources. Link to comment
roaddog Posted May 26, 2016 Share Posted May 26, 2016 My guess is you need to put share param to 1. options : List of key=value pairs separated by semicolons. Supported keys are:share which can be set to 0 or 1. (Default value for SQLite is "share=1", for MySQL is "share=0"). When set to 1, the connection is shared and will be used by other calls to dbConnect with the same host string. Link to comment
Bonsai Posted May 26, 2016 Author Share Posted May 26, 2016 dbConnect is only used once by that resource. Other resources just use the connection. But I discovered another problem with this now. After some hours, the queries started to fail and the Error was "Expected db-connection, got marker". I have no idea how that could happen... Bonsai Link to comment
roaddog Posted May 26, 2016 Share Posted May 26, 2016 I tried the code its working just fine, maybe you have other element rather than the db assigned to it. Its weird. Link to comment
Anubhav Posted May 26, 2016 Share Posted May 26, 2016 Weird. Really very weird. function Database.main() Database.connection = dbConnect("mysql", "dbname=**;host=**" ,"**", "**") if not Database.connection then Database.connection = dbConnect("mysql", "dbname=**;host=**" ,"**", "**") if not Database.connection then outputDebugString("Database Connection failed!") end else outputDebugString("Database Connection successful!") end end addEventHandler("onResourceStart", resourceRoot, Database.main) function Database.kill() if isElement(Database.connection) then destroyElement(Database.connection) Database.connection = nil end outputDebugString("Database Connection killed!") end addEventHandler("onResourceStop", resourceRoot, Database.kill) function getConnection() return Database.connection end Try this tho Link to comment
Rataj Posted May 27, 2016 Share Posted May 27, 2016 After some hours, the queries started to fail and the Error was "Expected db-connection, got marker". That will be problem in another script where you set exported database connection to variable, you probably assigned marker to that variable. Link to comment
Bonsai Posted May 27, 2016 Author Share Posted May 27, 2016 I wish The connection is only used for some db functions in other resources. But by now I think the error message was just wrong. There is no way it can become a marker by script. Bonsai Link to comment
Noki Posted May 28, 2016 Share Posted May 28, 2016 https://wiki.multitheftauto.com/wiki/Sc ... ing_Reused Far fetched, but you shouldn't leave any stone unturned. It's a possibility that there's some other referencing error in one of your scripts, like others have suggested. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now