EntityFramework ConnectionString utf8

青春壹個敷衍的年華 提交于 2019-12-10 18:56:25

问题


I want to add utf8 support to my Entity Framework database application (sql server 2008 r2)

I think I need to add the charset to the connectionString.

This is how my connectionString works (anonymized, of course)

<add name="MyContainer" connectionString="metadata=res://*/MyDatabase.csdl|res://*/MyDatabase.ssdl|res://*/MyDatabase.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=myserver\instancename;Initial Catalog=MyCatalog;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD;MultipleActiveResultSets=True;&quot;" providerName="System.Data.EntityClient" />

I had a look at connectionstrings.com, but I found nothing regarding utf8.

I tried adding charset=utf8, but that doesn't do the trick.

 <add name="MyContainer" connectionString="metadata=res://*/MyDatabase.csdl|res://*/MyDatabase.ssdl|res://*/MyDatabase.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=myserver\instancename;Initial Catalog=MyCatalog;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD;MultipleActiveResultSets=True;charset=utf8;&quot;" providerName="System.Data.EntityClient" />

Results in a System.Data.EntityException: {"The underlying provider failed on ConnectionString."} {"Keyword not supported: 'charset'."}

Question:
How do I set the charset to utf8 in the connectionString? Or is utf8 enabled by default?


回答1:


Usage of unicode is defined by variable or column type. Char and varchar are non-unicode and nchar and nvarchar are unicode (UCS-2).

There are also collations which define code page for char and varchar columns and the way in which strings are compared and ordered. Each database has a default collation and each column or variable can have explicitly defined other collation.

Character set is not configured by connection.



来源:https://stackoverflow.com/questions/7203317/entityframework-connectionstring-utf8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!