SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQLState = 42S02, NativeError = 208


SQLState = 42S02, NativeError = 208

Author
Message
abdul88
abdul88
SSC Journeyman
SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)

Group: General Forum Members
Points: 94 Visits: 8
Hello and greetings to all expert, can anyone tell me why I getting this error message below:

SQLState = 42S02, NativeError = 208
Error = [Microsoft][SQL Native Client][SQL Server]Invalid object name 'TEST.dbo.users'.
SQLState = 42000, NativeError = 8180
Error = [Microsoft][SQL Native Client][SQL Server]Statement(s) could not be prepared.

For Code below:

SET @COLUMN_NAME='UserID'
SET @Database='TEST'
SET @table='users'

SET @DyQuery='SELECT '+@COLUMN_NAME+',* FROM '+@Database + '.dbo.' + @table+' WHERE '+@COLUMN_NAME+' LIKE '''' OR '+@COLUMN_NAME+' IS NULL'
SET @FileName=@Database + '.dbo.' + @table

SET @Command = 'bcp "'
+ @DyQuery
+ '" queryout "'
+ 'C:\'
+ @FileName --FileName, IF need a familiar name--
+ '_'
+ CONVERT(VARCHAR,YEAR(GETDATE())) --get year
+ CONVERT(VARCHAR,REPLACE(STR(MONTH(GETDATE()),2),' ','0')) --get month
+ CONVERT(VARCHAR,REPLACE(STR(DAY(GETDATE()),2),' ','0')) --get day
+ '.txt" -c -t -T -U da -P 123456 -S' + @@SERVERNAME + '\SQLEXPRESS'

EXEC xp_cmdshell @command


Is there any missing ? I do not know how to solve it. I already enable sp_configure for xp_cmdshell.
I also try to insert the Server name but it still pop the same error.
Kristen-173977
Kristen-173977
SSCertifiable
SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)

Group: General Forum Members
Points: 6858 Visits: 627
I would put PRINT statements after

SET @DyQuery=...

and before

EXEC xp_cmdshell @command

to see what those two variables contain. I would then try them manually, which will show errors more clearly, and then adjust the source code to generate any changes you make.

That said, they look fine to me.

"Invalid object name 'TEST.dbo.users'."

Does this give you some rows, or an error?

SELECT TOP 10 * FROM TEST.dbo.users


Kristen-173977
Kristen-173977
SSCertifiable
SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)

Group: General Forum Members
Points: 6858 Visits: 627
PS If it all works fine then try logging in as User = "da" Password="123456" and check that the SQL Query runs OK for that user
abdul88
abdul88
SSC Journeyman
SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)

Group: General Forum Members
Points: 94 Visits: 8
The PRINT function also been test, I think it the query is correct.

I try the SELECT statement and there is a row how data appear. No error occurs.

The username and the password also correct.

Not sure why this error pop out.

Thank you for the respond.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search