• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

Coldfusion SQL Server 2005 connectivity issue

Experts,

I'm having troubles getting SQL Server 2005 Express to recognize my CF queries. I had SQL Server and CF working properly but had hard drive issues and had to reformat. I've reinstalled everything but now I'm getting this error message on all queries:

 Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid object name 'color'.
 
The error occurred in C:\Inetpub\wwwroot\cfdocs\ruthSisters\store\test.cfm: line 11

9 :
10 : <!--- <cfquery name="getCategories" datasource="#request.db#" username="#request.username#" password="#request.password#"> --->
11 : <cfquery name="getCategories" datasource="ruthsisters" username="sa" password="xxxxxxx">
12 :       SELECT      *
13 :       FROM      color
14 : </cfquery>

"Color" is the name of a column in the database.

The install for both CF and SQL I believe is fine. I'm concerned because usually I've assigned port 1433 to the SQL db in the CF admininistrator. The only way CF will verify the db is if I use port 1259. I've went into Windows administrative tools and established an ODBC connect which is verified. I believe that I have everything as before but something is not working.

Thank you for any help you can give!!!!!

rr
0
rruth
Asked:
rruth
1 Solution
 
aseusaincCommented:
The FROM field should be referencing a table name within the database, not a column name.

Try

SELECT color
FROM tablename
0
 
rruthAuthor Commented:
I'm sorry color is a table in the database not a column.

rr
0
 
ExpertAdminCommented:
It sounds to me like you need to change SQL Server's configuration to use port 1433 instead of 1259.

M@
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
rruthAuthor Commented:
ExpertAdmin,

I went into the SQL Server Configuration Manager, clicked on Protocols for SQLEXPRESS, right clicked on TCP/IP and clicked on Properties and changed the port  from 1259 to 1433. I then went back into CF Admin/datasource and changed the port there to 1433. I get the same error message: Invalid object name.

I don't know what else to do. I really appreciate your help!!!

rr
0
 
boy8964Commented:
Why don't you try to use cf administrator to set up a DNS for you. When you finshied setting DNS you can verify the connection. Make use it is working!
0
 
rruthAuthor Commented:
boy8964,

Again, originally I had SQL 2005 and CF working. After I reformatted by hard drive and re-installed everything, all my queries in the app I was working on through an error saying that the name of my table is invalid.

I've went into the CF Admin and verified the connection to my table. I've went into SQL Server Configuration Manager and changed the port from 1259 to 1433. I've also went into Windows Admin tools and verified the ODBC connection there.

I'm really desparate. I now have reformatted by hard drive twice hoping that I had done something wrong the first time!!!!!!!!!!

I really, no I mean I REALLY appreciate any help you can give!

rr
0
 
ExpertAdminCommented:
OK...if you are getting an error stating that the name of your table is invalid then you are getting through to SQL Server. That is a SQL error, not a connection error.

It sounds to me like you now have the wrong default database selected in your connection. It defaults to "Master" which would prevent your queries from seeing your tables. There is an easy way to test this:

Modify one of your queries to fully qualify the table name. For example, if you have a table named Customer in a database named Sales, use this syntax on a select statement:

SELECT * FROM Sales..Customer

instead of

SELECT * FROM Custome

If this works then you have the wrong default database selected in your connection. An easy fix. If this does not work, please copy the error and paste it in a reply so we can see exactly what it is complaining about.

Thanks,

M@
0
 
rruthAuthor Commented:
ExpertAdmin,

You are going the right direction with this. What I did is create a query that used the DNS for my database (ruthsisters) but actually used a table (spt_values) that is in the master database and it worked, returning every value in a column called "Name". Here is a look at the query:

<cfquery name="getMaster" datasource="ruthsisters" username="sa" password="xxxxxx">
      SELECT *
      FROM      spt_values
</cfquery>

<cfoutput query="getMaster">
      #Name#<br />
</cfoutput>

How can I get SQL to find my database?

Again, THANK YOU for you help!

rr
0
 
ExpertAdminCommented:
Go back to your DSN and set the Default Database property to your database. There should be a setting that will allow you to choose it from a dropdown list.

M@
0
 
rruthAuthor Commented:
ExpertAdmin,

I found that if I add the option: dbname="ruthsisters" to my query it finds the correct database. I uploaded the test query to my ISP with the "dbname" option and it functions normally there. I'm not sure why after re-installing SQL Server that I now have to include the "dbname" option. This means that I will do a search and replace on all queries to add this option so they work properly on my local development computer. I can live with this. If you have any insight on why the change I would really appreciate knowing.

<cfquery name="getAdmin" datasource="ruthsisters" username="sa" password="xxxxxxx" dbname="ruthsisters">
      SELECT *
      FROM      admin
</cfquery>

It was your clue that SQL Server was defaulting to the master db that helped me work this out. I really appreciate your help and if you know why this happened I would love to know also!

rr
0
 
ExpertAdminCommented:
Again, I don't think that SQL Server is the real problem. Were you able to set the default DB in your ODBC connection?

M@
0
 
rruthAuthor Commented:
ExpertAdmin,

No I was not able to locate the place to make that selection. I'm finding that I'm still having some problems. After adding the "dbname" attribute to the example query above, the query functioned as expected. But even with the dbname attribute added some of my queries are still throwing the same error message. This is really frustrating because these are all queries that functioned properly before the melt down of my hard drive. Do you have any suggestions where I can make this selection?

Again, thanks for your help!

rr
0
 
ExpertAdminCommented:
I am assuming that your DSN is set up in Windows. If that is the case, you can go to Control Panel, ODBC Connections, then click on the Machine Data Sources tab. You should see a list of DSNs, and yours should be in that list. If you double click on the name, you should get a dialog that lets you set the username, password, and default database.

Here are the step by step instructions:

http://www.depts.ttu.edu/helpcentral/directions/ODBCSetup.php

M@
0
 
rruthAuthor Commented:
ExpertAdmin,

I went into the Windows Admin Tools and found the default db option you mentioned. While there I noticed that I had mistakenly setup my database under the System DSN tab instead of the User DSN. I removed it and than re-added it under User. Pretty lame! I never changed my default settings and all my queries are now working. Thank you again for sending me in the right direction and going the extra mile!!!

rr
0
 
ExpertAdminCommented:
That is great news. You are welcome.

One thing...you should be able to use either a system or a user DSN the same with no problems. The main difference is that a user DSN will only be visible when you are logged in. If you are setting up a server DSN you will need to make sure it is a System, not User DSN because otherwise it will not be available when you are not logged in.

M@
0
 
rruthAuthor Commented:
ExpertAdmin,

That makes sense. Thank you for all your help!

rr
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now