逃离“在实体框架连接字符串中

时间:2018-02-08 20:37:17

标签: entity-framework-6 sqlanywhere

对于SQL Anywhere 17,我们需要在连接后进行autenticate,我将其设置为InitString,当我执行SAConnection.Connect

时这很有效。
<add key="connectionString" value="UID=dba;PWD=***;Host=10.10.10.10:2638;InitString='SET TEMPORARY OPTION CONNECTION_AUTHENTICATION=&quot;Company=Quick Systems AS;Application=EQ Timing;Signature=xxxx...xxx&quot;'"/> 

但是当使用Entity Framework时,这个字符串已编码一次:

<add name="TimingConnection" connectionString="metadata=res://*/Timing.csdl|res://*/Timing.ssdl|res://*/Timing.msl;provider=Sap.Data.SQLAnywhere;provider connection string=&quot;UserID=dba;Password=sql;Host=10.10.10.10&quot;" providerName="System.Data.EntityClient"/>

如何添加身份验证InitString

<add name="TimingConnection" connectionString="metadata=res://*/Timing.csdl|res://*/Timing.ssdl|res://*/Timing.msl;provider=Sap.Data.SQLAnywhere;provider connection string=&quot;UserID=dba;Password=sql;Host=10.10.10.10;InitString='SET TEMPORARY OPTION CONNECTION_AUTHENTICATION=&quot;Company=Quick Systems AS;Application=EQ Timing;Signature=xxx...xxx&quot;'&quot;" providerName="System.Data.EntityClient"/>

我得到的错误是初始化字符串的格式不符合从索引98开始的规范。

1 个答案:

答案 0 :(得分:0)

要在连接字符串内部进行转义,我需要将&quot;加倍,因此它是&quot;&quot;

<add name="TimingConnection" connectionString="metadata=res://*/Timing.csdl|res://*/Timing.ssdl|res://*/Timing.msl;provider=Sap.Data.SQLAnywhere;provider connection string=&quot&quot;;UserID=dba;Password=sql;Host=10.10.10.10;InitString='SET TEMPORARY OPTION CONNECTION_AUTHENTICATION=&quot;Company=Quick Systems AS;Application=EQ Timing;Signature=xxx...xxx&quot;&quot;'&quot;" providerName="System.Data.EntityClient"/>