当前提供程序不支持命令参数 - 我该怎么办?
我正在尝试查询 Microsoft Indexing Service 目录,并且发现了很多关于它的非常有用的文章(例如 这个),但是我发现每个例子都只是使用字符串连接来构建查询,而且在很多不同的层面上感觉都是错误的。
我显然想使用参数化查询,但看起来 MS 索引提供程序不支持它们,如以下异常所述:
“MSIDXS”提供程序不支持 ICommandWithParameters 接口。当前提供程序不支持命令参数。
这是我的代码的简化示例。我想做的就是运行一个非常简单的查询,并防止错误的输入。
OleDbCommand cmd = new OleDbCommand("select DocTitle, Path from scope() where @friendlyName = '@value'", ActiveConnection());
cmd.Parameters.Add(new OleDbParameter("@friendlyName", friendlyName));
cmd.Parameters.Add(new OleDbParameter("@value", value));
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet results = new DataSet();
da.Fill(results);
如果我真的被迫使用字符串连接,那么清理输入的最佳方法是什么?我怎么知道我涵盖了所有案例?
I'm trying to query the Microsoft Indexing Service catalog, and I've found a bunch of really helpful articles about it (like this one), but every example I find they just use string concatenation to build queries, and it feels so wrong on so many different levels.
I clearly want to use parameterized queries, but it looks like the MS Indexing provider doesn't support them, as described by the following exception:
The ICommandWithParameters interface is not supported by the 'MSIDXS' provider. Command parameters are unsupported with the current provider.
Here's a simplified example of my code. All I want to do is run a really simple query, and protect against bad input.
OleDbCommand cmd = new OleDbCommand("select DocTitle, Path from scope() where @friendlyName = '@value'", ActiveConnection());
cmd.Parameters.Add(new OleDbParameter("@friendlyName", friendlyName));
cmd.Parameters.Add(new OleDbParameter("@value", value));
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet results = new DataSet();
da.Fill(results);
If I'm really forced to use string concatenation, what's the best way to sanitize the inputs? How will I know I covered all the cases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参数必须有名称吗?看起来这个 msdn 示例可能符合要求。
http://msdn.microsoft.com/ en-us/library/system.data.oledb.oledbcommand.parameters.aspx
Do the parameters have to have names? Looks like this msdn example might fit the bill.
}
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.parameters.aspx