首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebMatrix + MySQL链接

WebMatrix + MySQL链接
EN

Stack Overflow用户
提问于 2012-03-07 11:47:20
回答 1查看 3.2K关注 0票数 1

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

web.config:

代码语言:javascript
复制
<?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>

代码:

代码语言:javascript
复制
@{
    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>

错误

代码语言:javascript
复制
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连接器,但仍然收到错误:

代码语言:javascript
复制
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:

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-07 15:57:12

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

http://www.connectionstrings.com/mysql

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9595531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档