简体   繁体   中英

Invalid object name when trying to insert into a temp table

I'm trying to monitor a mirrored copy of a database. I am running a script that is also capable of performing other checks and some of them are very similar to then one that is causing me problems.

Code that works:

  conn.execute "if object_id('tempdb..#logs') is not null drop table tempdb..#logs"
  conn.execute "create table #logs (...'a lot of variables)"
  conn.execute "insert into #logs exec('dbcc sqlperf (logspace)')"

Code that does not work:

  conn.execute "if object_id('tempdb..#mirrors') is not null drop table tempdb..#mirrors"
  conn.execute "create table #mirrors (...'alot of variables)"
  conn.execute "insert into #mirrors exec('msdb..sp_dbmmonitorresults "&db&",1,0')"

The error on invalid object comes when trying to execute the insert in the second example. Is it possible that the string including all of the variables is to long?

I have never worked with Visual Basic before so this might be something obvious.

I have tried to run the code in the SQL server manegment studio and it works perfectly.

Does anyone have any ideas?

G

I found the solution. The problem was that I had an open "ADODB.recordset". So when I called "conn.execute" it logged out after each execution and there for it wasn't the same session as before and the temp table was deleted before I could insert into it.

I found out by using the SQL profiler.

Thanks for the help.

G

The problem may not be your code, but a problem with SQL Server itself. I think that there are cases where the log shipping objects can be improperly installed. If you read Spanish then there's an MSDN forum discussion which looks like it might be useful. Unfortunately, I don't read Spanish, I can't use Google translate behind this firewall, and I couldn't find out anything else about it.

The full error that I get when I try to run your code:

Msg 208, Level 16, State 1, Procedure sp_dbmmonitorresults, Line 137 Invalid object name 'msdb.dbo.dbm_monitor_data'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM