<!--- Set the connection variables --->
<cfset serverIP = "192.168.1.11">
<cfset dbName = "infiniti_adbuilder">
<cfset username = "_infiniti_">
<cfset password = "infiniti123">
<cfset sqlString = "select region, id, Buildprovince from dealers">
<!--- Create the connection to the server --->
<!---<cfset ConnectString="Provider=MSDASQL;DSN=infiniti;UID=_infiniti_;PWD=infiniti123;">--->
<cfset ConnectString="Provider='SQLOLEDB';Server='#serverIP#';Initial Catalog='#dbName#'">
<cfobject type="COM" name="ConnectionObject" class="ADODB.Connection" action=""> <cfset discard = ConnectionObject.Open(ConnectString,"#username#","#password#",0)>
<!--- Run the query --->
<cfset myResultSet = ConnectionObject.Execute("#sqlString#",0,8)>
<!--- Get the column names --->
<cfset Columns = "">
<cfloop collection="#myResultSet.Fields#" item="thisField">
<cfset Columns = listappend(Columns, thisField.name)>
</cfloop>
<!--- Populate a newly made query with Columns --->
<cfset MyRecords = querynew(Columns)>
<!--- Go to the first row of the recordset --->
<cfset myResultSet.movefirst()>
<!--- And populate the recordset... --->
<cftry>
<cfloop from="1" to="250000" index="i">
<cfif NOT myResultSet.EOF>
<cfset queryaddrow(MyRecords, 1)>
</cfif>
<cfloop collection="#myResultSet.Fields#" item="this">
<cfset querysetcell(MyRecords, trim(this.name), this.value, i)>
</cfloop>
<cfset myResultSet.movenext()>
</cfloop>
<cfcatch></cfcatch>
</cftry>
<!--- Output the data --->
<table border="1">
<!--- output the columns --->
<tr> <cfoutput>
<cfloop index="thisColumn" list="#MyRecords.columnList#" >
<th>#thisColumn#</th>
</cfloop>
</cfoutput> </tr>
<!--- output the rows --->
<cfoutput query="MyRecords">
<tr>
<cfloop list="#MyRecords.columnlist#" index="this">
<td>#evaluate(this)#</td>
</cfloop>
</tr>
</cfoutput>
</table>
<!--- Close the ODBC connection (like you do in asp)--->
<cfset ConnectionObject.Close()>
the error I got is
An exception occurred when executing a Com method.
The cause of this exception was that: AutomationException: 0x80004005 - [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. in 'Microsoft OLE DB Provider for SQL Server'.
The error occurred in C:\Inetpub\wwwroot\dev\test2.cfm: line 12
10 : <cfset ConnectString="Provider='SQLOLEDB';Server='#serverIP#';Initial Catalog='#dbName#'">
11 : <cfobject type="COM" name="ConnectionObject" class="ADODB.Connection" action=""> 12 : <cfset discard = ConnectionObject.Open(ConnectString,"#username#","#password#",0)>
13 : <!--- Run the query --->
14 : <cfset myResultSet = ConnectionObject.Execute("#sqlString#",0,8)>
thanks
asim
> Thanks Kola,
> that article is a way back when CHARTFX was introduces, now their all
> syntax have been changed.
>
> The main thing which I am looking for is to find the way to run the
> query in ADODB syle in coldFusion.
> <!---Create the ADODB Connection and query the database--->
> <CFOBJECT ACTION="" NAME="Conn" CLASS="ADODB.Connection">
> <!---Open the ODBC data source--->
> <CFSET Conn.open("DSN=CfxSrv;UID=guest;","","0","0")>
> <!---Execute the SQL statement that will return the data--->
> <CFSET RS=Conn.Execute("SELECT Month,Sales,Projected From
> CIEDemoSales","","0")>
>
>
> the above query is connected with Access db, how can I use the same
> style query with SQL server.
>
> Thanks
> asim
>
>
> >:-(
> >
> >>Someone would have responded :-)
> >>
> >>> no
one???
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

