Set Database Connection durning runtime

Well I have looked everywhere and cant seam to find a way to set the project level database. I have central project that looks a several different machine that each have their own database. So when user selects machine I need to set the project database to that machines database. I could do this through client tag but would need to modify all of my many screens to use this client tag as their database.

I have done this as a test on screen that I though might have issues and indeed it does have issues. If I have any scripts that run a runPrepStmt command off of a table lets say they cant find the correct database.

Any ideas??

Unfortunately, you can’t change the project’s default database right now. You do have to go down the route of changing the database connection dynamically on all SQL queries. In the SQL query bindings you can link the datasource to the client tag. In scripting when you call system.db.runPrepUpdate or any of those functions you can specify the datasource connection:system.db.runPrepUpdate("INSERT INTO table (col1, col2) VALUES (?,?)", [val1, val2], "DatasourceConnection")Of course it could come from a tag:system.db.runPrepUpdate("INSERT INTO table (col1, col2) VALUES (?,?)", [val1, val2], system.tag.read("[Client]Datasource").value)

Thanks for confirming Travis that was what I was afraid of and have started down that path now.
Thanks Again

Hi @Travis.Cox, I am looking for exactly the same requirement to change the project default database connection in runtime for our project. At-least is it possible now(after 8 year) with 8.0 or 8.1.

Thanks,
Hari GB,

It is not possible. It is not considered necessary, since everywhere the default is applied, there is also the option to override it dynamically.

Hi @pturmel , Thanks for the promptness, This needed for me because, In a big project for multiple machines with same front pointing to different db’s. As this feature is not there i am forced to handle (through dbconnection parameter) this in all my quires right from scratch of the development process or the other way it may not be easy for me to have this change after the application got matured enough.

Yes, this is something best handled from the start.

If I were you, I’d get started fixing all your queries. Even if IA decides to support this, it would be many months before you’d see it. And with everything else they are working on, I doubt this would be a priority. It isn’t a bug, after all. And it isn’t a feature that has no other solution. Just a time-saver for developers that didn’t plan sufficiently far ahead. /:

Sure @pturmel , Thanks for the feedbacks. Let me start change it manually.