How do I programmatically create a new datasource?
The short answer is to use the Coldfusion Administrator API.
The following is taken directly from the ColdFusion documentation:
You can perform most ColdFusion MX Administrator tasks programmatically using the Administrator API. The Administrator API consists of a set of ColdFusion components (CFCs) that contain methods you call to perform Administrator tasks. For example, you use the setMSQL method of datasource.cfc to add a SQL Server data source.
// Login is always required. This example uses a single line of code. createObject("component","cfide.adminapi.administrator").login("admin");
// Instantiate the data source object. myObj = createObject("component","cfide.adminapi.datasource");
// Required arguments for a data source. stDSN = structNew();
stDSN.driver = "MSSQLServer";
stDSN.name="northwind_MSSQL";
stDSN.host = "10.1.147.73";
stDSN.port = "1433";
stDSN.database = "northwind";
stDSN.username = "sa";
// Optional and advanced arguments. stDSN.login_timeout = "29";
stDSN.timeout = "23";
stDSN.interval = 6;
stDSN.buffer = "64000";
stDSN.blob_buffer = "64000";
stDSN.setStringParameterAsUnicode = "false";
stDSN.description = "Northwind SQL Server";
stDSN.pooling = true;
stDSN.maxpooledstatements = 999;
stDSN.enableMaxConnections = "true";
stDSN.maxConnections = "299";
stDSN.enable_clob = true;
stDSN.enable_blob = true;
stDSN.disable = false;
stDSN.storedProc = true;
stDSN.alter = false;
stDSN.grant = true;
stDSN.select = true;
stDSN.update = true;
stDSN.create = true;
stDSN.delete = true;
stDSN.drop = false;
stDSN.revoke = false;
//Create a DSN. myObj.setMSSQL(argumentCollection=stDSN);
</cfscript>
This question was written by Jeremy Petersen.
It was last updated on February 15, 2007 at 9:55:50 AM EST.
CFML Referenced
Categories
Comments
Comment made by sLive on September 10, 2007 at 2:00 PM
I use it on my http://zurna.sohbetlive.com , http://www.mircarsivi.com , http://www.alpella.net and http://www.sohbetlive.net site's, http://www.aniden.net is my site!