I use WebMatrix to write my site (C#/MVC3) and I am using a local mysql server (not installed through webmatrix) to store all my data, so i tried to go to the Connections tab and add my server in there as a New Connection. But it just gives me an error no matter what i put for the Host. I know the db name, username & password are correct.
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>
Code:
@{
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>
Error
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)
Any help is greatly appreciated!
EDIT:
I installed the MySQL connector and i am still getting an error:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
I downloaded it from: http://dev.mysql.com/downloads/mirror.php?id=403991 and just installed it with the default settings. Am i supposed to install it into the webmatrix directory?!?
New 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>
You need to make up your mind whether you are using MySQL (as in the title of your post and the tag you chose) or Sql Server (as in the connection string). If you are using MySQL, you need a different connection string.
http://www.connectionstrings.com/mysql