[英]Error “invalid object name” after select into temporary table
I'm porting a working code to Microsoft Sql Server 2016 from a different dbms. 我正在将工作代码从其他dbms移植到Microsoft Sql Server 2016。 The sql looks like SQL看起来像
SELECT many_fields INTO #this_repository FROM complex_join WHERE parametric_cond
I open the connection 我打开连接
OdbcCommand server_cmd = new OdbcCommand(SQL_extractor_server, DbConnection);
OdbcParameter refresh_from_par = new OdbcParameter("@refresh_from",refresh_from);
OdbcParameter refresh_to_par = new OdbcParameter("@refresh_to",refresh_to);
server_cmd.Parameters.Add(refresh_from_par);
server_cmd.Parameters.Add(refresh_to_par);
server_cmd.ExecuteNonQuery();
server_cmd.Dispose();
and then execute some commands always inside that connection. 然后总是在该连接内部执行一些命令。
OdbcCommand tot_rows_cmd = new OdbcCommand("SELECT COUNT(*) AS 'tot_rows' FROM #this_repository",DbConnection);
tot_rows = (int)tot_rows_cmd.ExecuteScalar();
tot_rows_cmd.Dispose();
Can you explain the error or suggest where to look at? 您能解释该错误或建议在哪里查看吗? Thank you! 谢谢!
System.Data.Odbc
to System.Data.SqlClient
我已将代码和连接字符串从System.Data.Odbc
移至System.Data.SqlClient
Pooling=false;
我添加了Pooling=false;
to the connection string 到连接字符串 SELECT @@spid
from an ExecuteScalar
) to double check that the spid
is always the same 我插入了其他代码(仅是ExecuteScalar
的SELECT @@spid
)以仔细检查spid
始终相同 int
) of the first ExecuteNonQuery
and it is 0 我已经调试了第一个ExecuteNonQuery
的返回码( int
),它是0 SqlCommand
and two statements separated by ;
从C#代码尝试过,仅使用一个SqlCommand
和两个用' ;
分隔的语句 : that also does work but it is not what I'm trying to accomplish :也可以,但这不是我要完成的工作 Unfortunately no luck till now! 不幸的是,到目前为止没有运气!
It looks like a bug in ADO.NET 看起来像是ADO.NET中的错误
This answer clearly explains which is the root cause (and incidentally why it works in a Sql client): 该答案清楚地说明了根本原因(以及附带的原因,为什么它在Sql客户端中起作用):
I've tried by hard coding the parameters in the SQL and the issue doesn't show up. 我已经尝试通过在SQL中对参数进行硬编码来解决问题,但问题并未出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.