Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Datasource

Status
Not open for further replies.

aadeshm

Programmer
Dec 14, 2000
1
IN
Hello friends,

i m new to coldfusion. i just want to ask that is there any other alternative for defining DSN in CF . (like UDL in ASP).
 
Unless there's something new in CF 4.5, I think the answer is no. What are you trying to do as I'm not familiar with udl in asp? If you just want to know how to create a datasource outside of CF, then you can do that with the odbc manager but I'm guessing you want to somehow create datasources inside the app.

GJ
 
Hello friend :),

I haven't tested the following code (network settings here don't allow creating objects on the server, can you believe it...). I hope it works and this is what you mean.

<CFSCRIPT>
MyConn = CreateObject(&quot;COM&quot;, &quot;ADODB.Connection&quot;)
DSNtemp = &quot;DRIVER={Microsoft Access Driver (*.mdb)};&quot;
DSNtemp = DSNtemp &amp; &quot;DBQ=e:\data\myDatabase.mdb&quot;
MyConn.Open(&quot;#DSNtemp#&quot;, &quot;Username&quot;, &quot;Password&quot;, -1)

SQL = &quot;SELECT * FROM table&quot;

MyRecordset = MyConnection.Execute(SQL, 0, 8);

MyFields = MyRecordset.Fields;

/* Make a variable for recordcount */

RecordCount = 0;
while(NOT MyRecordset.EOF){
RecordCount = RecordCount + 1;
MyRecordset.MoveNext();
}

Columns = &quot;&quot;;
</CFSCRIPT>

<!--- Get the Column Name from the MyFields collections --->
<CFLOOP COLLECTION=&quot;#MyFields#&quot; ITEM=&quot;this&quot;>
<CFSET Columns = ListAppend(Columns, this.Name)>
</CFLOOP>

<!--- Populate a newly made query with columns --->
<CFSET MyRecords = QueryNew(Columns)>

<!--- Add 'RecordCount' rows to hold the data --->
<CFSET QueryAddRow(MyRecords, RecordCount)>

<!--- Go to the first row of the recordset --->
<CFSET MyRecordset.MoveFirst()>

<!--- And populate the recordset... --->
<CFLOOP FROM=&quot;1&quot; TO=&quot;#RecordCount#&quot; INDEX=&quot;i&quot;>
<CFLOOP COLLECTION=&quot;#MyFields#&quot; ITEM=&quot;this&quot;>
<CFSET QuerySetCell(MyRecords, Trim(this.name), this.value, i)>
</CFLOOP>
<CFSET MyRecordset.MoveNext()>
</CFLOOP>

<!--- Ouput the data like this: --->
<CFOUTPUT QUERY=&quot;MyRecords&quot;>
<TR>
<CFLOOP LIST=&quot;#MyRecords.ColumnList#&quot; INDEX=&quot;this&quot;>
<TD>#Evaluate(this)#</TD>
</CFLOOP>
</TR>
</CFOUTPUT>
</TABLE>

<!--- Close the ODBC connection (like you do in ASP)--->
<CFSET MyConnection.Close()>

Pretty impressive huh? If it doesn't work, don't get mad, and if it works, don't expect a great performance. CFQUERY is at least twice as fast, but hey, you've got a DSNless connection now, right :).
Good luck.
<webguru>iqof188</webguru>
 
pretty code, but what's the 8 in the Execute-Command?

--> MyRecordset = MyConnection.Execute(SQL, 0, 8);
 
This value indicates that the type of command in CommandText is not known(adCmdUnknown). This is the default value to command execute. It is not necessary to put it there, but thanks for noticing :).

Right now I'm curious if it worked... aadeshm, did it work?

<webguru>iqof188</webguru>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top