30 Jul 2010 
Support Center » Knowledgebase » ColdFusion Database Connections (DSNless)
 ColdFusion Database Connections (DSNless)
Solution ColdFusion database connections (DSNless)

The following article explains how to create a DSNless connection to a database. DNSless connections are direct connections to a database that do not require a ColdFusion Administrator to make specific configurations. A DSNless connection can be used to connect to any type of database, including Microsoft SQL and Microsoft Access.

To create a DSNless connection, add the following snippet of code within your application.cfm page or to each individual page that should connect to a database:

< cfscript >

classLoader = createObject("java", "java.lang.Class");
classLoader.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dm = createObject("java","java.sql.DriverManager");

con = dm.getConnection(connection string);

st = con.createStatement();
rs = st.ExecuteQuery("Select * FROM table");
q = createObject("java", "coldfusion.sql.QueryTable").init(rs);

< /cfscript >

The connectionstring will depend on the type of connecting database. The following are two common connectionstring examples:

Microsoft SQL
"jdbc:odbc:DRIVER={SQL Server};Database="dbname";Server=192.168.0.0;", "login", "password"

Microsoft Access
"Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\websites\folder\mydatabase.mdb;Uid=;Pwd=;"

Note: If you use either of the above examples, you will need to change the information to refer to your database.


Article Details
Article ID: 47
Created On: 09 Sep 2006 01:48 PM

 Back
 Login [Lost Password] 
Email:
Password:
Remember Me:
 
 Search
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Troubleshooter | News | Downloads
Language:

Help Desk Software Help Desk Software By Kayako SupportSuite v3.70.02