Unix Technical Forum

Correct access to TempDB?

This is a discussion on Correct access to TempDB? within the SQL Server forums, part of the Microsoft SQL Server category; --> From vb6 i try to do this: 'STEP 1 sSql = "IF OBJECT_ID('tempdb..#tabella') IS NOT NULL DROP TABLE #tabella" ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 06:37 AM
zMatteo
 
Posts: n/a
Default Correct access to TempDB?

From vb6 i try to do this:

'STEP 1
sSql = "IF OBJECT_ID('tempdb..#tabella') IS NOT NULL DROP TABLE #tabella"
m_cn.Execute sSql, RowAff

'STEP 2
sSql = "SELECT top 0 * INTO #tabella_temp FROM tabella" & vbCrLf
m_cn.Execute sSql, RowAff

'STEP 3
sSql = "insert into #tabella_temp select * FROM tabella" & vbCrLf
m_cn.Execute sSql, RowAff

but at step 3 i've this ADO 2.7 error:
number: -2147217865
description: Invalid object name '#tabella_temp'.

why?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 06:37 AM
Simon Hayes
 
Posts: n/a
Default Re: Correct access to TempDB?


"zMatteo" <origma@edpsistem.it> wrote in message
news:dd31d194.0501140852.3e6d5188@posting.google.c om...
> From vb6 i try to do this:
>
> 'STEP 1
> sSql = "IF OBJECT_ID('tempdb..#tabella') IS NOT NULL DROP TABLE #tabella"
> m_cn.Execute sSql, RowAff
>
> 'STEP 2
> sSql = "SELECT top 0 * INTO #tabella_temp FROM tabella" & vbCrLf
> m_cn.Execute sSql, RowAff
>
> 'STEP 3
> sSql = "insert into #tabella_temp select * FROM tabella" & vbCrLf
> m_cn.Execute sSql, RowAff
>
> but at step 3 i've this ADO 2.7 error:
> number: -2147217865
> description: Invalid object name '#tabella_temp'.
>
> why?


It works fine for me in VBScript, but I guess you're doing something extra
between steps 2 and 3 (if not, then you could just remove "TOP 0" from step
2 and forget about step 3) - is the connection being closed at some point?

You could also use Profiler to check what's going on and see exactly what
commands are being sent to the server.

Simon


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 06:38 AM
Erland Sommarskog
 
Posts: n/a
Default Re: Correct access to TempDB?

[posted and mailed, please reply in news]

zMatteo (origma@edpsistem.it) writes:
> From vb6 i try to do this:
>
> 'STEP 1
> sSql = "IF OBJECT_ID('tempdb..#tabella') IS NOT NULL DROP TABLE
> #tabella" m_cn.Execute sSql, RowAff
>
> 'STEP 2
> sSql = "SELECT top 0 * INTO #tabella_temp FROM tabella" & vbCrLf
> m_cn.Execute sSql, RowAff
>
> 'STEP 3
> sSql = "insert into #tabella_temp select * FROM tabella" & vbCrLf
> m_cn.Execute sSql, RowAff
>
> but at step 3 i've this ADO 2.7 error:
> number: -2147217865
> description: Invalid object name '#tabella_temp'.


ADO is trying to be helpful, but gets it all wrong. What it should
have done - in my opinion - is to yell and scream and shout that
you cannot execute any commands on that connection right now, because
you have unfetched results. This you have because you have not consumed
all your recordsets by looping with .NextRecords set. Neither did you
pass adExecuteNorRecords to execute, to inform that you don't care about
the result set. A third option would be to have run SET NOCOUNT ON
prior to the operation so that were would be no result sets. (The
result sets are really the row counts.)

What ADO does of yelling, is to open a second connection to SQL
Server behind your back. Sometimes this saves the show. In this
case it doesn't.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:06 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com