序列化/反序列化连接字符串应该区分大小写吗?
如何以区分大小写的方式反序列化字符串?看起来序列化是区分大小写的,反序列化不区分大小写有什么意义?
更新:尝试本地化幕后发生的位置和内容,我已设置 DEBUGGER 来下载符号并进入 FCL .NET 代码。我一直坚持这些代码(DbConnectionOptions.cs 第 873-921 行):
private static NameValuePair ParseInternal(Hashtable parsetable, string connectionString, bool buildChain, Hashtable synonyms, bool firstKey) {
Debug.Assert(null != connectionString, "null connectionstring");
StringBuilder buffer = new StringBuilder();
NameValuePair localKeychain = null, keychain = null;
int nextStartPosition = 0;
int endPosition = connectionString.Length;
while (nextStartPosition < endPosition) {
int startPosition = nextStartPosition;
string keyname, keyvalue;
nextStartPosition = GetKeyValuePair(connectionString, startPosition, buffer, firstKey, out keyname, out keyvalue);
if (ADP.IsEmpty(keyname)) {
// if (nextStartPosition != endPosition) { throw; }
break;
}
string realkeyname = ((null != synonyms) ? (string)synonyms[keyname] : keyname);
if (!IsKeyNameValid(realkeyname)) {
throw ADP.KeywordNotSupported(keyname);
}
修改发生在 while 循环内的某个位置,该循环在每次迭代中查找另一个键/值对。不幸的是,我无法将“添加监视”添加到 keyname 和 realkeyname 变量中。我想同义词哈希表在这里也很重要。
- 我怎样才能看到这些变量值?
- 接下来我该怎么做才能最终找到修改的确切位置?
How can I deserialize a string in case-sensitive way? It looks like serialization is case-sensitive, what's the point in deserialization being not case-sensitive??
UPDATE: trying to localize where and what is going on under the hood, I've set up DEBUGGER to download symbols and stepped into the FCL .NET code. I've stuck near these code (DbConnectionOptions.cs lines 873-921):
private static NameValuePair ParseInternal(Hashtable parsetable, string connectionString, bool buildChain, Hashtable synonyms, bool firstKey) {
Debug.Assert(null != connectionString, "null connectionstring");
StringBuilder buffer = new StringBuilder();
NameValuePair localKeychain = null, keychain = null;
int nextStartPosition = 0;
int endPosition = connectionString.Length;
while (nextStartPosition < endPosition) {
int startPosition = nextStartPosition;
string keyname, keyvalue;
nextStartPosition = GetKeyValuePair(connectionString, startPosition, buffer, firstKey, out keyname, out keyvalue);
if (ADP.IsEmpty(keyname)) {
// if (nextStartPosition != endPosition) { throw; }
break;
}
string realkeyname = ((null != synonyms) ? (string)synonyms[keyname] : keyname);
if (!IsKeyNameValid(realkeyname)) {
throw ADP.KeywordNotSupported(keyname);
}
The modification occurs somewhere inside the while loop, which looks for another key/value pair in every iteration. Unfortunately I can't 'add watch' to keyname and realkeyname variables. I suppose synonyms Hashtable is also important here.
- how can I see these variable values?
- what should I do next to finally find the exact place of modification?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为(根据文档)对于连接字符串:
但是,这些值区分大小写(显然,对于密码等)
Because (as per the documentation) for connection strings:
The values, however, are case-sensitive (obviously, for passwords etc)
序列化肯定是区分大小写的,但是您的连接字符串不需要 - 您确定您的 ConnectionString 属性没有做一些奇怪的事情,例如:
请注意,
SqlConnectionStringBuilder
似乎会执行某些情况连接字符串的“规范化”,即“怪异”不一定需要出现在您的代码中。尝试在调试器中执行
info.GetValue("ConnectionString", typeof(string));
并查看返回的结果。Serialisation definitely is case sensitive, however your connection string doesn't need to be - are you sure that your ConnectionString property isn't doing something weird, for example:
Note that the
SqlConnectionStringBuilder
appears to do some case "normalisation" of connection strings, i.e. the "weirdness" doesn't necessarily need to be in your code.Try executing
info.GetValue("ConnectionString", typeof(string));
in a debugger and seeing what you get back.