我使用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>发布于 2012-03-07 15:57:12
您需要决定是使用MySQL (在帖子的标题和您选择的标记中)还是Sql Server (在连接字符串中)。如果您使用的是MySQL,则需要不同的连接字符串。
http://www.connectionstrings.com/mysql
https://stackoverflow.com/questions/9595531
复制相似问题