问题
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="Data Source=myserver\instancename;Initial Catalog=MyCatalog;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD;MultipleActiveResultSets=True;"" 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="Data Source=myserver\instancename;Initial Catalog=MyCatalog;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD;MultipleActiveResultSets=True;charset=utf8;"" 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