我試圖將我用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