数据库连接字符串和排序规则 [英] Database connection string and collation
问题描述
是否可以在MySql连接字符串中设置连接排序规则,以及如何设置连接排序规则,因为服务器上存在用于新连接的默认设置.
Is it possible to set connection collation within MySql connection string and how, since there's a default setting on the server that's used for new connections.
我不能做的两件事:
-
打开连接后无法调用并不完全如您在编辑中看到的那样SET COLLATION_CONNECTION
,因为我使用的是为我做所有调用的Entity Framework - 由于其他数据库及其使用它们的受尊敬的应用程序,因此无法更改服务器的默认连接排序规则.
Can't callnot entirely true as you may see in the editSET COLLATION_CONNECTION
after I open a connection, because I'm using Entity Framework that does all the calls for me- Can't change server default connection collation because of other databases and their respected applications that use them.
我想指定的只是我的web.config文件中的某个连接字符串参数,例如:
All I'd like to specify is a certain connection string parameter in my web.config file like:
"User id=dbuser;Password=dbpass;Host=dbserver;Database=testung;Collation=utf8_general_ci"
但无法识别Collation
设置/变量.
but Collation
setting/variable isn't recognised.
- Asp.net MVC 2
- IIS 7
- 实体框架1
- DevArt dotConnect MySql连接器
- MySql 5.1
我尝试了此代码,因为@Devart建议,但无济于事:
I've tried this code as @Devart suggested but to no avail:
partial void OnContextCreated()
{
System.Data.Common.DbCommand command = this.Connection.CreateCommand();
command.CommandText = "set collation_connection = utf8_slovenian_ci;";
command.CommandType = System.Data.CommandType.Text;
this.Connection.Open();
command.ExecuteNonQuery();
// this.Connection.Close();
}
推荐答案
我们建议您实现OnContextCreated局部方法.
您可以访问其中的存储连接,并且可以使用此连接执行ADO.NET命令"SET COLLATION = ...".
We recommend you to implement the OnContextCreated partial method.
You have access to the store connection in it and you can execute ADO.NET command "SET COLLATION = ..." using this connection.
这篇关于数据库连接字符串和排序规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!