调用存储过程不返回任何内容

发布于 2024-09-19 17:30:50 字数 1992 浏览 3 评论 0原文

我在 sql server 上调用一个存储过程,如下所示:

SqlConnection conn = new SqlConnection();
SqlCommand cmd;
XmlDocument xmlDocument;
XmlReader xr;
XmlNode node;
SqlDataReader rdr = null;

try
{
    xmlDocument = new XmlDocument();
    conn.ConnectionString = "Data Source=test;Initial Catalog=teste;Integrated Security=SSPI;";
    cmd = new SqlCommand();
    cmd.Connection = conn;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "[dbo].[spSearchKeywords]";

    cmd.Parameters.Add(new SqlParameter("@VALUE", "XPT"));

    conn.Open();

    xr = cmd.ExecuteXmlReader();

    conn.Close();
    node = xmlDocument.ReadNode(xr);
}

它连接并执行命令,但它什么也不返回 有数据要返回并且参数是正确的(当我使用相同的参数调用sql中的过程时,它会返回结果)

这里是过程:

ALTER PROCEDURE [dbo].[spSearchKeywords]
(
    @VALUE                 NVARCHAR(50)  = NULL,
    @ACCOUNTGROUPID         NVARCHAR(50)  = NULL,
    @ShortCodeId         NVARCHAR(50)  = NULL,
    @VALUETYPE             NVARCHAR(50)  = NULL,
    @ASSEMBLY             NVARCHAR(100) = NULL,
    @ASSEMBLYCONTAINSURI NCHAR   (10)  = NULL,
    @ASSEMBLYTYPE         NVARCHAR(50)  = NULL
)
AS
BEGIN

    SET NOCOUNT ON;

    SELECT [Value]
          ,[AccountGroupId]
          ,[ShortCodeId]
          ,[ValueType]
          ,[assembly]
          ,[assemblyContainsUri]
          ,[assemblyType]
      FROM [teste].[dbo].[keywords]
     WHERE [Value]                 = ISNULL(@VALUE,                [Value])
       AND [AccountGroupId]         = ISNULL(@ACCOUNTGROUPID,        [AccountGroupId])
       AND [ShortCodeId]         = ISNULL(@SHORTCODEID,            [ShortCodeId])
       AND [ValueType]             = ISNULL(@VALUETYPE,            [ValueType])
       AND [assembly]             = ISNULL(@ASSEMBLY,            [assembly])
       AND [assemblyContainsUri] = ISNULL(@ASSEMBLYCONTAINSURI, [assemblyContainsUri])
       AND [assemblyType]         = ISNULL(@ASSEMBLYTYPE,        [assemblyType])
     FOR XML AUTO
END

I am calling a stored procedure on sql server like this:

SqlConnection conn = new SqlConnection();
SqlCommand cmd;
XmlDocument xmlDocument;
XmlReader xr;
XmlNode node;
SqlDataReader rdr = null;

try
{
    xmlDocument = new XmlDocument();
    conn.ConnectionString = "Data Source=test;Initial Catalog=teste;Integrated Security=SSPI;";
    cmd = new SqlCommand();
    cmd.Connection = conn;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "[dbo].[spSearchKeywords]";

    cmd.Parameters.Add(new SqlParameter("@VALUE", "XPT"));

    conn.Open();

    xr = cmd.ExecuteXmlReader();

    conn.Close();
    node = xmlDocument.ReadNode(xr);
}

its connecting and executing the command, however it returns nothing
there is data to return and the parameters are correct(when I call the procedure in sql with the same parameter it returns me a result)

here is the proc:

ALTER PROCEDURE [dbo].[spSearchKeywords]
(
    @VALUE                 NVARCHAR(50)  = NULL,
    @ACCOUNTGROUPID         NVARCHAR(50)  = NULL,
    @ShortCodeId         NVARCHAR(50)  = NULL,
    @VALUETYPE             NVARCHAR(50)  = NULL,
    @ASSEMBLY             NVARCHAR(100) = NULL,
    @ASSEMBLYCONTAINSURI NCHAR   (10)  = NULL,
    @ASSEMBLYTYPE         NVARCHAR(50)  = NULL
)
AS
BEGIN

    SET NOCOUNT ON;

    SELECT [Value]
          ,[AccountGroupId]
          ,[ShortCodeId]
          ,[ValueType]
          ,[assembly]
          ,[assemblyContainsUri]
          ,[assemblyType]
      FROM [teste].[dbo].[keywords]
     WHERE [Value]                 = ISNULL(@VALUE,                [Value])
       AND [AccountGroupId]         = ISNULL(@ACCOUNTGROUPID,        [AccountGroupId])
       AND [ShortCodeId]         = ISNULL(@SHORTCODEID,            [ShortCodeId])
       AND [ValueType]             = ISNULL(@VALUETYPE,            [ValueType])
       AND [assembly]             = ISNULL(@ASSEMBLY,            [assembly])
       AND [assemblyContainsUri] = ISNULL(@ASSEMBLYCONTAINSURI, [assemblyContainsUri])
       AND [assemblyType]         = ISNULL(@ASSEMBLYTYPE,        [assemblyType])
     FOR XML AUTO
END

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对风讲故事 2024-09-26 17:30:50

在实际使用 XmlReader 之前,您无法关闭连接。尝试将 conn.Close() 放在 node = xmlDocument.ReadNode(xr); 下面。并考虑一次性数据库对象的 using 语句。

You can't close your connection before actually using the XmlReader. Try dropping the conn.Close() below node = xmlDocument.ReadNode(xr);. And consider the using statement for your disposable database objects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文