不支持MySQL关键字:C#应用程序中的“端口"错误 [英] MySQL Keyword not supported: 'port' error in C# application
问题描述
我正在尝试在我的C#.Net应用程序中连接到MySQL数据库
I am trying to connect to MySQL database in my c# .Net application
尝试连接时出现此错误:关键字不受支持:端口".
I am getting this error when I try to connect: Keyword not supported: 'port'.
错误似乎表明我的连接字符串有问题
The error appears to indicate an issue with my connection string
<add name="mydataEntities" connectionString="server=myserver.com;port=3306;password=xxxx;user id=yyyy;database= mydatabase;persistsecurityinfo=True" providerName="MySql.Data.MySqlClient" />
我为以下内容添加了参考: MySql.Data 6.9.7.0(MySQL的ADO.Net驱动程序) 和MySql.Data.Entity.EF6 6.9.7.0(支持Entity Framework 6.0)
I have reference added for: MySql.Data 6.9.7.0 (ADO.Net driver for MySQL) And MySql.Data.Entity.EF6 6.9.7.0(Entity Framework 6.0 supported)
在我的配置中,我有:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
</provider>
</providers>
</entityFramework>
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.9.7.0" newVersion="6.9.7.0" />
</dependentAssembly>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
在此处设置连接字符串:
connection string is set here:
public class Repository
{
protected mydataEntities DbContext;
public Repository()
{
DbContext = new mydataEntities (ConfigurationManager.ConnectionStrings["mydataEntities"].ConnectionString);
}
}
我注意到堆栈跟踪似乎正在使用System.Data.SqlClient提供程序,如下所示:
I notice the stack trace appears to be using the System.Data.SqlClient provider as shown below:
我删除了MySql.Data和MySql.Data.Entity.EF6引用,清理了解决方案,添加了引用,然后重新构建……..
I have removed the MySql.Data and MySql.Data.Entity.EF6 references, Clean solution , add back references then rebuild …..
任何人都可以帮助我找出此错误的根源吗?
Can anyone help me to figure out the source of this error?
为什么我的mysql连接器不使用我的配置中指定的providerName:MySql.Data.MySqlClient.
Why isn’t the MySQL connector using providerName: MySql.Data.MySqlClient as specified in my config.
at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
at System.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential)
at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
at System.Data.Entity.Infrastructure.SqlConnectionFactory.CreateConnection(String nameOrConnectionString)
at System.Data.Entity.Infrastructure.LocalDbConnectionFactory.CreateConnection(String nameOrConnectionString)
at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName()
at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName()
at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(DbContext context)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
推荐答案
以下是解决方法:
我从覆盖基类中的连接字符串的部分类中删除了以下代码.
I removed the following code from a partial class that overrides the connection string n the base.
public partial class mydataEntities
{
public mydataEntities(string connectionString) : base(connectionString) { }
}
我仍然对该解决方案感到困惑,但是似乎使用此代码,该连接正在尝试使用Mssql数据提供程序而不是MySql
I am still confused by the solution but it appears that with this code the connection was attempting to use the Mssql data provider instead of MySql
这篇关于不支持MySQL关键字:C#应用程序中的“端口"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!