[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference amcucs::ms-sqlsvr

Title:Microsoft SQL Server Support
Notice:Please Registar, Note #11
Moderator:AMCUCS::BETTS
Created:Tue Aug 23 1994
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:382
Total number of notes:1233

349.0. "#ODBC# stored procedures filling tempdb" by NEWVAX::RAK () Sun Mar 16 1997 23:25

    We've developed a few SQL Server based programs.
    One (or more) of them is misbehaving - Tempdb fills up 
    with #ODBC#* stored procedures.  The number of database 
    connections often increases to the max allowed.
    
    Is there a way to see the SQL inside these sp_ODBC
    procedures?  It would help us isolate our misbehaving 
    code.  
    
    Any idea what coding practice would cause them not to 
    be dropped?
T.RTitleUserPersonal
Name
DateLines
349.1EPS::VANDENHEUVELHeinSun Mar 16 1997 23:597
    
    Hmm, can you influence this with the 'do no generate stored procedure'
    check box in the odbc setup screen in the control panel on the CLIENT ?
    
    	hth,
    		Hein.
    
349.2ODBC stored proceduresNETRIX::"laodennis@mail.dec.com"Dennis LaoMon Mar 17 1997 01:5745
When an ODBC enabled application uses prepared execution to execute an SQL
query on SQL Server and the user has permission to create stored procedures,
the ODBC SQL Server driver creates a stored procedure with a name like
"odbc#userid########" (for example, odbc#sa2147024896) on SQL Server and
executes that stored procedure.

The stored procedure is created in response to a SQLPrepare ODBC call and is
executed when SQLExecute is called. Normally, when the connection is closed,
the driver drops these stored procedures. Also, if the user does not have
Create Proc permissions, the stored procedures are not created and SQL
statements are executed directly. 

However, under certain situations when a connection might be terminated
without closing the connection, the driver is not able to delete the stored
procedures. This can happen if the client process terminates abnormally and is
a more common occurrence in a development environment. 

You can create a script to delete these stored procedures when all ODBC
clients have disconnected from the server:

      USE  <database_name>
      go
      SELECT CHAR(13) + CHAR(10)+ "DROP PROCEDURE " + NAME +
             CHAR(13) + CHAR(10) + "go" +
             CHAR(13) + CHAR(10)
      FROM sysobjects
      WHERE name LIKE "ODBC%"
      go

As a workaround, you can revoke permissions to create stored procedures from
the users and the SQL Server driver will not create these stored procedures.
The drawback is that your queries may run significantly slower.

Prepared execution is an efficient way to execute a statement more than once.
It is commonly used by vertical and customer applications to repeatedly
execute the same, parameterized SQL statement e.g. the MS Jet Engine.

You should run something like ODBC SPY or just enable the trace facility in
the ODBC manager to get an idea of what SQL statements are being passed to the
Server and determine whether disabling "prepared execution" will affect
performance.

Hope this helps,
Dennis.
[Posted by WWW Notes gateway]
349.3CSC32::HOEPNERA closed mouth gathers no feetMon Mar 17 1997 14:153
    
    If you are running 6.5 SQL Server you can use SQL TRACE to see what
    sql commands are being run at the server level. 
349.4Missing disconnects caused problemNEWVAX::RAKMon Mar 17 1997 17:587
    Thanks to all!
    
    The hypothesis mentioned in .2 - clients not disconnecting cleanly was
    indeed our problem.  We had a mismatch between connects and disconnects in
    certain code paths that eventually consumed all resources.
    
    
349.5CSC32::HOEPNERA closed mouth gathers no feetMon Mar 17 1997 19:452
    
    Thanks for the update.