what's wrong with my DELETE FROM query?

D

darrel

I'm still struggling to find out why I keep getting

Invalid object name 'monkey'.

errors. Below is my try/catch statement. Note the first query is trying to
delete a record in the table MONKEY. If I omit this, it performs the second
query just fine, but it always hang on this first one.

I've copied this MONKEY table into a new, differently named table, but still
get the same error. I can run this query within Enterprise manager, and it
executes just fine.

The issue with the error seems to be that it can't find the table, but it is
clearly there, so I am completely stumped as to what to check next in
determining the source of my error.

-----------------------

Try
Dim strConnect As String
strConnect =
System.Configuration.ConfigurationSettings.AppSettings("DBConnProduction")
Dim strChk1 As String = "DELETE FROM monkey WHERE UserID='" &
Request.QueryString("UserID") & "'"
Dim strChk2 As String = "DELETE FROM we_admin_linkUsersToCategories WHERE
UserID='" & Request.QueryString("UserID") & "'"

Dim objConnect As New System.Data.OleDb.OleDbConnection(strConnect)
objConnect.Open()
Dim objCommand1 As New System.Data.OleDb.OleDbCommand(strChk1,
objConnect)
objCommand1.ExecuteNonQuery()
Dim objCommand2 As New System.Data.OleDb.OleDbCommand(strChk2,
objConnect)
objCommand2.ExecuteNonQuery()

objConnect.Close()
objCommand1.Dispose()
objCommand2.Dispose()
objCommand1 = Nothing
objCommand2 = Nothing
objConnect = Nothing

catch
'error stuff
end try

-Darrel
 
M

Marina

What does 'hangs' mean? Is there an error? If so, what is the error message?
If you mean the statement never finishes executing then you are having some
sort of transaction/locking issue.

In either case, grabbing the userid from the query string and just putting
it right into a SQL statement is just asking for a SQL injection attack. I
suggest you do a google search on that.
 
J

Joshua Flanagan

You my need to specify the schema owner prefix on the table name. If the
owner is not 'dbo', and you are not using the schema owner's name in the
connection string, you will need to specify the owner.

Example (when not logging in as joeuser, and MONKEY was created by joeuser):

DELETE FROM joeuser.monkey WHERE ...


For easier testing, try running the command from SQL Query Analyzer
while logged in using the same account used in your connection string.
 
D

darrel

What does 'hangs' mean? Is there an error? If so, what is the error

Invalid object name '[table name]'.
In either case, grabbing the userid from the query string and just putting
it right into a SQL statement is just asking for a SQL injection attack.

This is all internal. Part of our internal CMS. We're also checking
permissions on all delete functions prior to execution.

-Darrel
 
D

darrel

You my need to specify the schema owner prefix on the table name.

'doh!

We figured it out. Our DB moved to a different server, but no one deleted
the old one (or forgot to tell us it moved ;o)

So, I was looking at a copy of the DB that I was actually trying to update.

NEVERMIND! ;o)

-Darrel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top