Is there any easy way to create multiple datasource by any script?

Hey Guys,

I’m finding a solution to create multiple datasource by any script? because I have 50+ database to configure with Lucee. I’m doing manually by Lucee admin panel so I am looking for a good solution though. I would really appreciated if anyone has any solution out there!!

Note: Which file has stored these details on the server side?

Regards,
Abhilash S V

Don’t forget to tell us about your stack!

OS: ???
Java Version: ???
Tomcat Version: ???
Lucee Version: ???

Cfconfig https://cfconfig.ortusbooks.com/

1 Like

You will need to tweak this a bit as I write terrible code and no I didnt check this as its roughly what I have, but cant copy due to work obligations.

Create a database in mysql or something with all 50 of your other database,usernames, passwords, connection settings, You can then do something like this.


<CFLOOP QUERY="qDatabases">
  <CFOUTPUT>

  
 <cffile action = "write" 
file = "C:\lucee\tomcat\webapps\root\application_dsn.defaults.txt" 
output = "C:\lucee\tomcat\webapps\root\application_dsn.defaults.#now#.txt"
#this.datasources["#qDatabases.QconnectName#"] = {
  class: '#qDatabases.QconnectClass#'
  bundleVersion: '#qDatabases.Qversion#'
  connectionString: '#qDatabases.QConnStatic#://#qDatabases.host#:#qDatabases.port#/#qDatabases.QconnectName#?characterEncoding=UTF-8&serverTimezone=America/New_York&maxReconnects=3'
  username: "#qDatabases.username#"
  password: "encrypted:#qDatabases.password#"
  }
  ;
  <--- next ---> 
  
  
  
</CFLOOP>

</cfoutput>

there are examples for scripting datasources via application.cfc at the bottom of the edit datasource page in the admin

to do it programmatically

the server configuration is stored in
C:\lucee\tomcat\lucee-server\context\lucee-server.xml

the web configuration is stored in
C:\lucee\tomcat\webapps\ROOT\WEB-INF\lucee\lucee-web.xml.cfm

1 Like

Thanks for the reply @Terry_Whitney, @Zackster
Let me see them and will update you if its helps me!