【发布时间】:2014-04-29 18:07:18
【问题描述】:
我有以下 ADO.Net C# 代码用于执行带参数的存储过程。当我观察分析器时,它被列为
exec uspSecurityGetChildActivitiesByInternalName @ActivityInternalName = N'INVWLVIEWEDIT'
但我希望它被修改为
exec uspSecurityGetChildActivitiesByInternalName @ActivityInternalName = 'INVWLVIEWEDIT'
我需要在参数值之前避免N。这应该是可能的,因为在我拥有的原始跟踪中,它没有N(尽管我没有源代码)。
我们如何修改以下 C# 代码以在没有 N 的情况下在分析器中创建 exec 语句?
参考
- Can SQL Profiler display return result sets alongside the query?
- Exception when AddWithValue parameter is NULL
代码:
using (SqlCommand command = new SqlCommand(spName, connection))
{
WriteLogFunction(spStatement);
command.CommandType = System.Data.CommandType.StoredProcedure;
if (paramsList.Count > 0)
{
foreach (Parameter p in paramsList)
{
command.Parameters.AddWithValue(p.MyParameterName, p.MyVal);
}
}
string resultVal=String.Empty;
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
resultVal = reader.GetString(0);
}
}
}
//Other code
}
【问题讨论】:
-
为什么?
N表示值作为 unicode 传递 -
@YuriyGalanter 我需要这个才能使用默认设置;不指定 unicode
-
是否所有参数都传递给了 SP 字符串? SP 中定义的它们的大小是多少?
-
你说你想要,你说你需要,但你没有说为什么。如果我们更了解您,可能会更容易提出有用的建议。
-
@TaW 我正在尝试从跟踪文件中执行所有 SP。参考stackoverflow.com/questions/2086713/…