【发布时间】:2014-04-07 14:45:37
【问题描述】:
我有这个 SQL Server 存储过程:
SET NOCOUNT ON
EXECUTE sp_configure 'Show Advanced Options', 1
RECONFIGURE
EXECUTE sp_configure 'Ad Hoc Distributed Queries', 1
RECONFIGURE
SELECT UserName, LoggedState, InteractionId, InteractionType --<-- The columns required.
FROM
OPENROWSET('SQLNCLI'
,'Server=USER-PC\SQLEXPRESS;Trusted_Connection=yes;database=XXX'
,'EXECUTE dbo.[XXX]')
当我在 SQL Server Management Studio 中执行它时,我得到了这个结果:
我的问题
我需要从表中读取数据。
我的问题
此数据不在输出参数中。这就是我无法阅读它们的原因。
我尝试过的
string vmpgraph = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
SqlConnection Graphsqlcon = new SqlConnection(vmpgraph);
SqlCommand GraphCmd = new SqlCommand("storedProcedureName", Graphsqlcon);
SqlParameter tdate = new SqlParameter();
GraphCmd.CommandType = CommandType.StoredProcedure; ;
SqlDataAdapter DAGraph = new SqlDataAdapter(GraphCmd);
DataSet DSGraph = new DataSet();
DSGraph.Clear();
DAGraph.Fill(DSGraph);
DataTable DTgraph = new DataTable();
DTgraph = DSGraph.Tables[0];
这是正确的吗?如果不是,我该怎么办?
我无法在真实数据库上测试我的代码,因为我还没有数据库。
【问题讨论】:
-
看来您知道问题所在以及导致问题的原因!但不清楚你在哪里挣扎!
-
@huMptyduMpty 我告诉了你我的代码。我说我不知道代码是否应该工作代码,或者这不是您从存储过程接收数据的方式
-
消息选项卡中显示什么?我假设如果您在 USER-PC\SQLEXPRESS 上调用
EXECUTE dbo.[XXX],您会得到结果。 -
@Wojtek 它显示了这个
Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install. Configuration option 'Ad Hoc Distributed Queries' changed from 1 to 1. Run the RECONFIGURE statement to install. (1 row(s) affected) (1 row(s) affected)不要担心这个,我知道是什么原因造成的 -
@user2226785:你会在某个时候拥有一个数据库吗?
标签: c# sql sql-server database