Connection string and database mapping

Is it possible to establish connection mapping in the MySql connection string and how, since the server uses the default setting for new connections.

Two things I can not do :

  • I can’t call SET COLLATION_CONNECTIONafter I open the connection, because I use the Entity Framework, which makes all the calls to me not quite true, as you can see in edit
  • It is not possible to change the default server connection setting due to other databases and their respected applications that use them.

All I would like to specify is a specific connection string parameter in my web.config file, for example:

"User id=dbuser;Password=dbpass;Host=dbserver;Database=testung;Collation=utf8_general_ci"

but Collationsetting / variable is not recognized.

Used technologies

  • Asp.net MVC 2
  • IIS 7
  • Entity Framework 1
  • MyArt dotConnect MySql Connector
  • MySql 5.1

EDIT 1

I 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();
}
+2
source share
2 answers

We recommend that you execute the partially processed OnContextCreated method.

You have access to the store’s connection in it, and you can execute the ADO.NET "SET COLLATION = ..." command using this connection.

+1
source

If someone else encounters this problem or wants to issue a command when opening a connection: the answer to OnContextCreated no longer works, as this method no longer exists / is no longer supported.

, SET NAMES <character set used by the database>, ;initialization command=\"SET NAMES '" + CharSet + "';\" . Devart, PostgreSQL, MSSQL Oracle

EntityDeveloper Advanced.

0

All Articles