Solved

Execute SQL using ADO

Posted on 2001-06-19
8
185 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
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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now