我试图将我用Visual Studio创建的mvc网站连接到MySQL。 使用SqlServer时,我的网站工作得很好。Visual Studio 2013 MVC MySql连接
在我的web.config我说:
<connectionStrings>
<add name="MySqlConnection" connectionString ="Server=localhost;port=3306;Database=BachelorParty;Uid=root;Pwd=root;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
没有与用户 '根' 和密码 '根' 在MySQL Workbench中登录没有问题。
在我的DbContext类我说:
[DbConfigurationType(typeof(MySqlEFConfiguration))]
当我运行了整个事情,我得到一个NullReferenceException在Global.asax中:
Database.SetInitializer(new BachelorPartyInitializer());
new BachelorPartyContext().Students.ToList(); //<--nullreferenceexception
在刷新服务器资源管理器中会发生以下情况:
Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message:
Access denied for user 'root'@'localhost' (using password: NO)
关于修复这个道德败坏问题的任何想法? EntityFramework,MySql.Data,MySql.Data.Entities,MySql Connector等安装...
排除 '端口= 3306' 你是100%肯定,你的ConnectionString是确定的?参看我的回答是,我不得不排除'port = 3306' – Seneca