【发布时间】:2014-04-03 06:23:02
【问题描述】:
我正在尝试将使用 Visual Studio 创建的 mvc 网站连接到 MySQL。 使用 SqlServer 时,我的网站运行良好。
在我的 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 中使用用户“root”和密码“root”登录没有问题。
在我的 DbContext 类中我添加了:
[DbConfigurationType(typeof(MySqlEFConfiguration))]
当我运行整个程序时,我在 global.asax 中得到一个 nullreferenceexception:
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等都安装好了...
【问题讨论】:
标签: mysql asp.net-mvc database-connection visual-studio-2013