Embedded SQL Database Reference


I have a program where I'm attempting to execute a SQL query that references a table that exists on another database.  It's the last line before the "if":

            Sql = Sql & "FROM CCLCache.dbo.CustomersExported)"

It's giving me the error "invalid object name" for that table, but I know it exists in that database.  What more do I need?
Who is Participating?
Daniel WilsonConnect With a Mentor Commented:
When you try it in SSMS / Query Analyzer, are you using the same credentials your application uses?

It could be a matter of rights on the CCLCache database.
Daniel WilsonCommented:
Are you sure it belongs to the DBO schema?

And what is the rest of your SQL statement?

And is the database on the same server as the one against which you're actually executing the statement?
NigelRocksAuthor Commented:
Yes, the database is on the same server.

Dang, I thought I'd attached the snippet...
        Sql = "SELECT cu_acct_num, Customer_Id, Acct_Type_Id, Cu_Name "
        Sql = Sql & "FROM Customer "
        If vExcludeExported Then 'The table used here, is now on local SQL server, must change query to work
            Sql = Sql & "WHERE cu_acct_num "
            Sql = Sql & "NOT IN (SELECT CustomerId "
            Sql = Sql & "FROM CCLCache.dbo.CustomersExported)"
        End If

Open in new window

Daniel WilsonCommented:
Do you get the same error if you execute the query in SSMS / Query Analyzer?
NigelRocksAuthor Commented:
No, it works perfectly there,.
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.

All Courses

From novice to tech pro — start learning today.