Connection String for MySQL, VS2010 Pro, ASP .NET MVC3

旧时模样 提交于 2019-12-07 05:09:27

问题


Background

I'm following this tutorial, but instead of using SQL Compact, I'd like to use MySQL. I'm having trouble with the connection string needed for this connection.

I've installed MySQL Connector v6.4.4.

I'm now trying to compose the connection string.

Where I'm stuck

I'm trying to create a Controller by right-clicking Controllers > Add Controller. I select the Movie Model and the MovieDBContext Context. I receive an error saying "Unable to retrieve metadata".

Connection strings attempted

  1. I've tried the basic connection string in hopes that Entity would automatically try to use the MySQL connector:

    Server=localhost;Database=MovieDB;Uid=root;Pwd=pass;
    
  2. I've tried the method used here, and I get another "Unable to retrieve metadata" error.

Is there any way to make this work with MySQL?


回答1:


The important part is: MySql.Data.MySqlClient

<add name="MovieDBContext"
         connectionString="Server=localhost;Database=MovieDB;Uid=root;Pwd=pass;"
         providerName="MySql.Data.MySqlClient"/>

I know... the question is old, but I tripped over this aswell, so here the answer.




回答2:


using MySql.Data.MySqlClient;

string ConnectionString = "database=MovieDB;server=localhost;uid=root;pwd=pass";

MySqlConnection Connection = new MySqlConnection(ConnectionString);

Connection.Open();



来源:https://stackoverflow.com/questions/7785769/connection-string-for-mysql-vs2010-pro-asp-net-mvc3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!