【问题标题】:WebMatrix + MySQL LinkingWebMatrix + MySQL 链接
【发布时间】:2012-03-07 03:47:20
【问题描述】:

我使用 WebMatrix 编写我的站点 (C#/MVC3),并且我使用本地 mysql 服务器(不是通过 webmatrix 安装)来存储我的所有数据,所以我尝试转到 Connections 选项卡并在其中添加我的服务器作为New Connection。但无论我为Host 输入什么,它都会给我一个错误。我知道数据库名称、用户名和密码是正确的。

web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <connectionStrings>
        <add connectionString="Uid=username;Server=localhost;Database=mydb;Pwd=pass" name="localhost" providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

代码:

@{
    Page.Title = "Comics";

    var db = Database.Open("localhost");
    var comics = db.Query(@"SELECT * FROM comics ORDER BY arc ASC").ToList();
}

<h1>@Page.Title</h1>

<ul class="thumbnails gallery">
    @foreach (var comic in comics) {
        <li>@comic.Arc</li>
    } 
</ul>

错误

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

非常感谢任何帮助!

编辑:

我安装了 MySQL 连接器,但仍然出现错误:

Unable to find the requested .Net Framework Data Provider.  It may not be installed. 

我从http://dev.mysql.com/downloads/mirror.php?id=403991 下载了它,并使用默认设置安装了它。我应该将它安装到 webmatrix 目录中吗?!?

新的 web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <connectionStrings>
        <add connectionString="Server=localhost;Database=mydb;Uid=user;Pwd=pass;" name="localhost" providerName="MySql.Data.MySqlClient.MySqlConnection" />
    </connectionStrings>
</configuration>

【问题讨论】:

    标签: mysql webmatrix


    【解决方案1】:

    您需要决定是使用 MySQL(如您的帖子标题和您选择的标签)还是 Sql Server(如连接字符串)。如果您使用的是 MySQL,则需要不同的连接字符串。

    http://www.connectionstrings.com/mysql

    【讨论】:

    • 我应该使用哪一个?我尝试了该页面上的第一个,但没有成功。
    • 没关系,我没有安装连接器...去图大声笑谢谢!
    • 好吧,我安装了连接器,它仍然说连接器丢失。从这里得到它:dev.mysql.com/downloads/mirror.php?id=403991。我必须将它安装在 webmatrix 目录中吗?
    • 找到另一个演示并让它工作。比我预期的要难:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    • 2011-09-24
    • 1970-01-01
    相关资源
    最近更新 更多