MySQL、VS2010 Pro、ASP .NET MVC3 的连接字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7785769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:22:16  来源:igfitidea点击:

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

mysqlvisual-studio-2010asp.net-mvc-3connection-string

提问by SB2055

Background

背景

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

我正在学习教程,但我想使用 MySQL,而不是使用 SQL Compact。我在处理此连接所需的连接字符串时遇到问题。

I've installed MySQL Connector v6.4.4.

我已经安装了 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".

我正在尝试通过右键单击控制器 > 添加控制器来创建控制器。我选择了 Movie Model 和 MovieDBContext Context。我收到一条错误消息“无法检索元数据”。

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.

  1. 我已经尝试了基本的连接字符串,希望 Entity 会自动尝试使用 MySQL 连接器:

    Server=localhost;Database=MovieDB;Uid=root;Pwd=pass;
    
  2. 我已经尝试了这里使用的方法,但我收到了另一个“无法检索元数据”错误。

Is there any way to make this work with MySQL?

有什么办法可以使这个与 MySQL 一起工作吗?

回答by xeed

The important part is: MySql.Data.MySqlClient

重要的部分是: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.

我知道......这个问题很老,但我也被这个问题绊倒了,所以这里是答案。

回答by user997287

using MySql.Data.MySqlClient;

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

MySqlConnection Connection = new MySqlConnection(ConnectionString);

Connection.Open();

使用 MySql.Data.MySqlClient;

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

MySqlConnection Connection = new MySqlConnection(ConnectionString);

Connection.Open();