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
User Comments
Add a Comment
Sharing is good. So if you have a comment about this entry please feel free to share. The Comments might be reviewed by our Staff and might require approval before being posted. Questions posted will not be answered, please submit a ticket for support requests.
Image verification required
Please enter the characters that appear to the right in the space provided. This is just to verify that you are a human.
Fullname:
Email: (Optional)
Comments:
Back
Login
[Lost Password]
Email:
Password:
Remember Me:
Search
-- Entire Support Site --
Knowledgebase
Downloads
Troubleshooter
Article Options
Add Comment
Print Article
PDF Version
Email Article
Add to Favorites
Home
|
Register
|
Submit a Ticket
|
Knowledgebase
|
Troubleshooter
|
News
|
Downloads
Language:
English (U.S.)
Help Desk Software
Help Desk Software By Kayako SupportSuite v3.70.02