6 Replies - 15452 Views - Last Post: 23 February 2010 - 05:38 PM Rate Topic: -----

#1 RedheadWebDev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-November 08

Data Source "name" could not be found - Error

Posted 15 November 2008 - 05:02 PM

I have a simple ColdFusion form on a contact page. When you press "submit" on the form I get the following error.

"Data source "name" could not be found"

The database is set up in MySql with no errors. I have added it in ColdFusion under "Data Sources" with no errors, status is OK.

In Dreamweaver I created the form. I viewed the database and table under the database tab. Then under "Server behaviors" I created a "insert record".

Form fields were linked up to the correct lines in the database table.

Below are the 2 secetions of code from that page.


 <cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>
<cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "CONTACT">
  <cfquery datasource="redhead">   
	INSERT INTO contact (name, email, company, findus, questions)
VALUES (<cfif IsDefined("FORM.name") AND #FORM.name# NEQ "">
<cfqueryparam value="#FORM.name#" cfsqltype="cf_sql_clob" maxlength="45">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.email") AND #FORM.email# NEQ "">
<cfqueryparam value="#FORM.email#" cfsqltype="cf_sql_clob" maxlength="45">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.company") AND #FORM.company# NEQ "">
<cfqueryparam value="#FORM.company#" cfsqltype="cf_sql_clob" maxlength="45">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.findus") AND #FORM.findus# NEQ "">
<cfqueryparam value="#FORM.findus#" cfsqltype="cf_sql_clob" maxlength="100">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.questions") AND #FORM.questions# NEQ "">
<cfqueryparam value="#FORM.questions#" cfsqltype="cf_sql_clob" maxlength="1000">
<cfelse>
''
</cfif>
)
  </cfquery>
  <cflocation url="contact_results.cfm">
</cfif>



Here is the next section of code

 <td><form action="<cfoutput>#CurrentPage#</cfoutput>" method="post" name="CONTACT">
			  <table width="298" border="0" cellpadding="5">
				<tr>
				  <td width="77" align="right"><strong>Your name:</strong></td>
				  <td width="195"><label>
					<input type="text" name="name" id="name">
				  </label></td>
				</tr>
				<tr>
				  <td align="right"><strong>E-mail Address:</strong></td>
				  <td><label>
					<input type="text" name="email" id="email">
				  </label></td>
				</tr>
				<tr>
				  <td align="right"><strong>Company:</strong></td>
				  <td><label>
					<input type="text" name="company" id="company">
				  </label></td>
				</tr>
				<tr>
				  <td align="right"><strong>How did you find us?</strong></td>
				  <td><label>
					<input type="text" name="findus" id="findus">
				  </label></td>
				</tr>
				<tr>
				  <td align="right"><strong>Questions:</strong></td>
				  <td></td>
				</tr>
				<tr>
				  <td colspan="2" align="center"><label>
					<textarea name="questions" id="questions" cols="35" rows="5"></textarea>
					<br>
					<br>
<input type="submit" name="SUBMIT" id="SUBMIT" value="Submit">
				  </label></td>
				  </tr>


Thanks so much for any help in advance - Redhead

Is This A Good Question/Topic? 0
  • +

Replies To: Data Source "name" could not be found - Error

#2 sansclue  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 316
  • Joined: 21-November 07

Re: Data Source "name" could not be found - Error

Posted 15 November 2008 - 06:59 PM

View PostRedheadWebDev, on 15 Nov, 2008 - 04:02 PM, said:

I have a simple ColdFusion form on a contact page. When you press "submit" on the form I get the following error.

"Data source "name" could not be found"


Does the error message literally say "name" or does it say "redhead"? If it says "name" that suggests the error is coming from a different page, or possibly the page you are running was not updated with the correct datasource name.

What happens if you create a test page and run this code only?

<!--- test adding a record to the table --->
<cfquery name="testInsertRecord" datasource="redhead">
INSERT INTO contact (name, email, company, findus, questions)
VALUES ('test name', 'test email', 'test company', 'test findus', 'test questions')
</cfquery>
Was This Post Helpful? 0
  • +
  • -

#3 RedheadWebDev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-November 08

Re: Data Source "name" could not be found - Error

Posted 16 November 2008 - 04:26 PM

Thank you so much for your help...

I did a test page with your code and I receive the same message.

Data Source redhead could not be found.

I am really stumped as to how to fix this... Thanks again for all of your help - Redhead
Was This Post Helpful? 0
  • +
  • -

#4 sansclue  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 316
  • Joined: 21-November 07

Re: Data Source "name" could not be found - Error

Posted 16 November 2008 - 07:38 PM

View PostRedheadWebDev, on 16 Nov, 2008 - 03:26 PM, said:

Thank you so much for your help...

I did a test page with your code and I receive the same message.

Data Source redhead could not be found.

I am really stumped as to how to fix this... Thanks again for all of your help - Redhead


Did you verify the spelling of the datasource name? Sometimes it can be something as simple as that, or an extra space in the name, etc... Assuming you have full control over ColdFusion, try the code below. It will print a success message if that datasource exists. Otherwise, it will display a list of the datasources that _do_ exist. Does the datasource "redhead" exist?

<cfset yourDSN = "redhead">
<cfset factory = createObject("java", "coldfusion.server.ServiceFactory")>
<cfset datasources = factory.getDataSourceService().getDatasources()>
<cfif structKeyExists(datasources, yourDSN)>
	<!--- show the datasources that do exist --->
	<b style="color: #008000;">Datasource Found!</b><br>
<cfelse>
	<b style="color: #ff0000;">Error - Datasource not found</b><br>
	<!--- show which datasources do exist --->
	<cfoutput>
	Existing datasources:<br><br>
	<cfloop collection="#datasources#" item="dsnName">
		#dsnName#<br>
	</cfloop>
	</cfoutput>
</cfif>


Was This Post Helpful? 1

#5 RedheadWebDev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-November 08

Re: Data Source "name" could not be found - Error

Posted 17 November 2008 - 12:27 PM

Here is the error that i received:

Security: The requested template has been denied access to createobject.
Was This Post Helpful? 0
  • +
  • -

#6 sansclue  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 316
  • Joined: 21-November 07

Re: Data Source "name" could not be found - Error

Posted 17 November 2008 - 05:46 PM

View PostRedheadWebDev, on 17 Nov, 2008 - 11:27 AM, said:

Here is the error that i received:

Security: The requested template has been denied access to createobject.


Yes, like I mentioned you need complete access to CF for that code to work. Just double check the name in the CF Administrator. Assuming the datasource really does exist on the server you are using, maybe there is a difference in spelling, case, spaces, etc..

BTW, what is your setup. Are you working with CF locally, or on a shared host?
Was This Post Helpful? 0
  • +
  • -

#7 Guest_JohnBond311*


Reputation:

Re: Data Source "name" could not be found - Error

Posted 23 February 2010 - 05:38 PM

I'm having the same problem.

The datasource does not show up when I run the code sansclue posted, but it is verified in cfadministrator.

I am using IIS on my local desktop, where CF8 and MySql 5 are both running. I tried pointing coldfusion to an Access db on my desktop too, and that doesn't show up even though it is verified in cfadministrator. Any datasource I add gives me the datasource not found error when I try to query it in code.

Any suggestions? Did you ever figure this out redhead?

Thanks
Was This Post Helpful? 0

Page 1 of 1