是否可以在 MySql 连接字符串中设置连接排序规则以及如何设置,因为服务器上有用于新连接的默认设置。
我不能做的两件事:
在打开连接后无法调用不完全正确,因为你可能会在编辑中看到SET COLLATION_CONNECTION
,因为我正在使用为我完成所有调用的 Entity Framework- 无法更改服务器默认连接排序规则,因为其他数据库及其相关应用程序正在使用它们。
我想指定的只是我的 web.config 文件中的某个连接字符串参数,例如:
"User id=dbuser;Password=dbpass;Host=dbserver;Database=testung;Collation=utf8_general_ci"
但是 Collation
设置/变量无法识别。
使用的技术
- ASP.NET MVC 2
- IIS 7
- Entity Framework 1
- DevArt dotConnect MySql 连接器
- MySql 5.1
编辑 1
我已经按照@Devart 的建议尝试了这段代码但无济于事:
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 = ...”。
关于mysql - 数据库连接字符串和排序规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2132530/