Page 1 of 1

Invalid connection string

Posted: Sat 06 Sep 2014 19:42
by dankolle
I start with the following code:

Code: Select all

			var builder = new MySqlConnectionStringBuilder();

			builder.Host = "----------";
			builder.Port = -----;
			builder.UserId = "--------";
			builder.Password = "------------";
			builder.Direct = true;
			builder.Database = "-------";
			builder.MaxPoolSize = 10;
			builder.ConnectionTimeout = 10;

			var conn2 = new Model.Entities(builder.ConnectionString);
When the code is executed I get the error "key is not supported 'user id'". I compared the string to the one Entity Developer shows me and they are basically the same.

I also tried this syntax: https://www.connectionstrings.com/mysql/

Am I using the wrong classes here?

Daniel

Re: Invalid connection string

Posted: Mon 08 Sep 2014 13:56
by Shalex
Looks like your Model.Entities(argument) constructor expects to receive EntityConnection object instead of the ADO.NET connection string. Try the code like this:

Code: Select all

    class Program
    {
        private static Entities _Entities;
        private static MetadataWorkspace _Workspace = new MetadataWorkspace(
            new[] { "res://*/DataModel1.csdl", "res://*/DataModel1.ssdl", "res://*/DataModel1.msl" },
            new[] { typeof(Entities).Assembly }
            );
        static void Main(string[] args)
        {
            var builder = new MySqlConnectionStringBuilder();

            builder.Host = "----------";
            builder.Port = -----;
            builder.UserId = "--------";
            builder.Password = "------------";
            builder.Direct = true;
            builder.Database = "-------";
            builder.MaxPoolSize = 10;
            builder.ConnectionTimeout = 10;

            EntityConnection entityConnection = new EntityConnection(_Workspace, new MySqlConnection(builder.ConnectionString);
            _Entities = new Entities(entityConnection);
        }
}