Solved

Execute SQL using ADO

Posted on 2001-06-19
8
204 Views
Last Modified: 2010-04-02
I am accessing a SQL 6.5 database and looking for some tables to drop. I am unable to get the query to work. I get an error msg saying that says {"Invalid column name 'CNV_TPB105_CHARGE_DETAIL_3'." (1)}.
This is a simple SQL query. Please help. what do I need to change.

if exists (select * from sysobjects where id = object_id("CNV_TPB105_CHARGE_DETAIL_3") and sysstat & 0xf = 3)
     drop table CNV_TPB105_CHARGE_DETAIL_3

The code to execute it:
          TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
          hr = pConnection->Open(strSQLDB,"","",NULL);
          pConnection->Execute(strExecString, NULL, NULL);
          pConnection->Close();
0
Comment
Question by:jsaxon2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:missionImpossible
ID: 6206342
maybe single quotes instead of "?
object_id('CNV_TPB105_CHARGE_DETAIL_3')
0
 
LVL 3

Author Comment

by:jsaxon2
ID: 6206600
I'm sorry, I copied the wrong SQL. It fails on the script below.


if exists (select * from sysobjects where id = object_id('dbo.CNV_TPB105_CHARGE_DETAIL_3') and sysstat & 
0xf = 3)
    drop table CNV_TPB105_CHARGE_DETAIL_3

I've narrowed it down to the dbo. prefix that is causing the problem. Is there anyway around this so that I would not get the error. The script is exactly what SQL Generate Scripts function produces and I don't want to have to change all of my table drops.
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 6208517
Are you using single or double quotes?  The first message implies that they are double, but they should be single, like in your second message.  That's what the error implies as well.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:MattC
ID: 6209722
how are you logging on the the database?
Are you loggin on as the dbo user, if not then you need to supply the owner prefix on tables you are accessing
0
 
LVL 3

Author Comment

by:jsaxon2
ID: 6210197
The exact syntax of the SQL is in the second post. It is using single quotes.

I am logging in using sa.


Fails:
if exists (select * from sysobjects where id = object_id('dbo.CNV_TPB105_CHARGE_DETAIL_3') and sysstat

0xf = 3)
   drop table CNV_TPB105_CHARGE_DETAIL_3


Works:
if exists (select * from sysobjects where id = object_id('CNV_TPB105_CHARGE_DETAIL_3') and sysstat & 0xf = 3)
   drop table CNV_TPB105_CHARGE_DETAIL_3


I want to find out why it thinks I'm looking for a column when it is prefixed with the dbo. alias. Thanks for you time.
0
 
LVL 1

Accepted Solution

by:
MattC earned 100 total points
ID: 6210485
is 'sa' the database owner of that DB
0
 
LVL 1

Expert Comment

by:MattC
ID: 6210554
and the tables
0
 
LVL 3

Author Comment

by:jsaxon2
ID: 6211841
The user 'sa' is the dbo. I have corrected the problem by using a different username and aliasing that user as 'dbo'. Also, I replaced the double quotes with the single quotes to help on some ALTER TABLE commands. I appreciate your time and knowledge.
Thank you,
John

P.S. If you could, please help explain why using the sa login does not work.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question