我有一个控制台应用程序,我通过Mono在Mac OS X上运行。虽然它在Windows操作系统上正确执行,但它只返回nvarchar(max)变量的第一个字符。这是C#代码:
SqlConnection myConnection = new SqlConnection(Variables.connectionString());
SqlCommand myCommand = new SqlCommand("IndexPageDetailsGet", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameterIndexPageID = new SqlParameter("@IndexPageID", SqlDbType.Int);
parameterIndexPageID.Value = indexPageID;
myCommand.Parameters.Add(parameterIndexPageID);
SqlParameter parameterIndexPageText = new SqlParameter("@IndexPageText", SqlDbType.NVarChar, -1);
parameterIndexPageText.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterIndexPageText);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
return (string)parameterIndexPageText.Value; // Only returns the first character
这是存储过程:
ALTER PROCEDURE [dbo].[IndexPageDetailsGet]
(
@IndexPageID int,
@IndexPageText nvarchar(max) OUTPUT
)
AS SELECT
@IndexPageText = IndexPageText
FROM
IndexPages
WHERE
IndexPageID = @IndexPageID
是否有其他人目睹了此行为和/或知道如何解决此问题?
编辑:这是我的单声道版本信息:
MonoDevelop 3.0.3.2
运行时间:
单声道2.10.9(tarball)
GTK 2.24.10
GTK#(2.12.0.0)
包装版本:210090011
答案 0 :(得分:0)
我找到了解决方法。我没有使用返回字符串的存储过程,而是使用了一个返回SqlDataReader的存储过程。然后它允许我一个具有完整nvarchar(max)值的字符串。因此,在C#中:
string indexPageText = string.Empty;
SqlConnection myConnection = new SqlConnection(Variables.connectionString());
SqlCommand myCommand = new SqlCommand("IndexPagesGetByIndexPageID", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameterIndexPageID = new SqlParameter("@IndexPageID", SqlDbType.Int);
parameterIndexPageID.Value = indexPageID;
myCommand.Parameters.Add(parameterIndexPageID);
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while (result.Read())
{
indexPageText = (string)result["IndexPageText"];
break;
}
result.Close();
indexPageDetails.indexPageText = indexPageText;
存储过程:
ALTER PROCEDURE
[dbo].[IndexPagesGetByIndexPageID]
(
@IndexPageID int
)
AS SELECT
*
FROM
IndexPages
WHERE
IndexPageID = @IndexPageID