2012-03-07 56 views
1

我使用WebMatrix来编写我的网站(C#/ MVC3),我使用本地mysql服务器(不是通过webmatrix安装)来存储我的所有数据,所以我试图去连接选项卡并添加我的服务器在那里作为New Connection。但无论我为Host投入了什么,它都会给我一个错误。我知道db名称,用户名为&的密码是正确的。WebMatrix + MySQL链接

的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> 

回答

2

你需要让你的心是否你正在使用MySQL(如在您的文章的标题和您选择的标签)或SQL Server(在连接串)。如果你使用MySQL,你需要一个不同的连接字符串。

http://www.connectionstrings.com/mysql

+0

我应该使用哪一个?我尝试了第一页,并没有奏效。 – rackemup420 2012-03-07 23:05:16

+0

从来没有结束,我没有安装连接器......去图笑哈谢谢! – rackemup420 2012-03-07 23:18:38

+0

那么我安装了连接器,它仍然说连接器丢失。从这里得到它:http://dev.mysql.com/downloads/mirror.php?id=403991。我必须将其安装在webmatrix目录中吗? – rackemup420 2012-03-09 15:13:51