M
Mike Hutton
I have a rather odd problem.
I have a SP which uses temp. tables along the way, and then returns a
table of results:
CREATE PROCEDURE dbo.usp_myproc(
@pNameList VARCHAR(6000)
)
AS
....
CREATE TABLE #MyTable (
Id INT
, Nm VARCHAR(255)
)
....
SELECT * FROM #MyTable;
GO
I am calling this using a "text" style SqlCommand, as follows:
SqlCommand pCommand = new SqlCommand("usp_myproc '" + namelist.Text +
"'");
pCommand.CommandType = CommandType.Text;
SqlConnection oConn = new SqlConnection(myConnectionString);
oConn.Open();
pCommand.Connection = oConn;
SqlDataAdapter oDtAd = new SqlDataAdapter(pCommand);
oDtAd.SelectCommand = pCommand; //new SqlDataAdapter(pCommand);
MyDataSet.Tables.Clear();
oDtAd.Fill(MyDataSet,"Results");
oConn.Close();
The oddity is that I'm getting back an Invalid Object exception -
"Invalid object name '#MyTable'"
If I take out the SELECT * FROM #MyTable and replace it with a select
from another table, it works fine.
If I change the table to a permanent table, the problem returns.
So it seems that the issue is one of using tables which have been
created in the same procedure.
It seems that the run of the stored proc is ignoring any DDL commands.
I have a large number of SPs which use temporary tables et al, and
these need to be accessed via ASP.NET
HELP!
From a security POV I am using a named user with db_owner access onto
both the target database and tempdb.
Any suggestions, anyone?
Mike.
I have a SP which uses temp. tables along the way, and then returns a
table of results:
CREATE PROCEDURE dbo.usp_myproc(
@pNameList VARCHAR(6000)
)
AS
....
CREATE TABLE #MyTable (
Id INT
, Nm VARCHAR(255)
)
....
SELECT * FROM #MyTable;
GO
I am calling this using a "text" style SqlCommand, as follows:
SqlCommand pCommand = new SqlCommand("usp_myproc '" + namelist.Text +
"'");
pCommand.CommandType = CommandType.Text;
SqlConnection oConn = new SqlConnection(myConnectionString);
oConn.Open();
pCommand.Connection = oConn;
SqlDataAdapter oDtAd = new SqlDataAdapter(pCommand);
oDtAd.SelectCommand = pCommand; //new SqlDataAdapter(pCommand);
MyDataSet.Tables.Clear();
oDtAd.Fill(MyDataSet,"Results");
oConn.Close();
The oddity is that I'm getting back an Invalid Object exception -
"Invalid object name '#MyTable'"
If I take out the SELECT * FROM #MyTable and replace it with a select
from another table, it works fine.
If I change the table to a permanent table, the problem returns.
So it seems that the issue is one of using tables which have been
created in the same procedure.
It seems that the run of the stored proc is ignoring any DDL commands.
I have a large number of SPs which use temporary tables et al, and
these need to be accessed via ASP.NET
HELP!
From a security POV I am using a named user with db_owner access onto
both the target database and tempdb.
Any suggestions, anyone?
Mike.