简体   繁体   English

String参数异常,为什么会发生这种情况?

[英]Exception with String argument, why is this happening?

I have : 我有 :

Dim con As New OleDbConnection(My.Resources.ConnectionString)

// Give exception = Format of the initialization string does not conform to specification starting at index 62.

When I substitute the actual value of the Resource, it give no exception : 当我替换Resource的实际值时,它没有例外:

Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\rawData.xlsx;Extended Properties=""Excel 12.0 XML;""")

The value of ConnectionString in Resources : Resources中ConnectionString的值:

 <data name="ConnectionString" xml:space="preserve">
    <value>Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\rawData.xlsx;Extended Properties=""Excel 12.0 XML;""</value>
 </data>

I don't understand why is this happening ? 我不明白为什么会这样?

I think this should have been replaced even before the compilation process.. 我认为即使在编译过程之前,也应该替换掉它。

Then why is it giving exception ? 那为什么给例外呢?

In the configuration file, you have double quotation marks around the Extended Properties values. 在配置文件中,“扩展属性”值周围有双引号。 Try removing them so you have only one. 尝试删除它们,以便只有一个。

The reason why it is working with the literal, is that in VB .NET, a double quotation mark escapes the quotation mark character so it can be used in a string without terminating the string. 之所以使用文字,是因为在VB .NET中,双引号会转义引号字符,因此可以在字符串中使用它而不必终止该字符串。 This does not apply to XML. 这不适用于XML。

You don't need the double quotes within the XML configuration file. 您不需要XML配置文件中的双引号。 It works fine when you substitute it, because "" is correctly escaped to a single " as it is a string literal. 当您替换它时,它可以正常工作,因为""已正确地转义为单个"因为它是字符串文字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM