Reputation: 43
I am not an expert by any means with C# and asp but I have managed to make it to the end of my site and deploy. Everything works fine locally including the MySQL connection. However when I plug in the connection string given by my host I get error messages. I have looked everywhere to find a solution and even contacted the host who was no help at all. I'm so frustrated and I know the best of the best are here. I'm sure there is a more than one issue with all my code. I was basic HTML and JS and SQL up until like 3 weeks ago. Than you everyone.
Web.Config file
<configuration>
<connectionStrings>
<add name="mySQLconn" connectionString="DRIVER={MySQL ODBC 5.1 Driver};server=skyhill.ipowermysql.com; user id=skyhillweb; password=******; database=skyhill; OPTION=3;"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
<authentication mode="None"/>
</system.web>
<system.webServer>
<defaultDocument>
<files>
<add value="/pages/default.aspx"/>
</files>
</defaultDocument>
</system.webServer>
</configuration>
Here is the page (just a test page) the path is pages/abc.aspx is you want to see the error.
<form id="form1" runat="server">
<asp:GridView ID="gridAgent" runat="server" AutoGenerateColumns="True">
</asp:GridView>
<asp:TextBox ID="MessageBox" runat="server">
</asp:TextBox>
</form>
and here is the C# behind the page
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.Common;
using MySql.Data.MySqlClient;
namespace SkhillWebApp.pages
{
public partial class abc : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["mySQLconn"].ConnectionString);
string strSQL = "SELECT agentID, FirstName, LastName FROM agent";
conn.Open();
MySqlDataAdapter mydata = new MySqlDataAdapter(strSQL, conn);
MySqlCommandBuilder cmd = new MySqlCommandBuilder(mydata);
DataSet ds = new DataSet();
mydata.Fill(ds);
gridAgent.DataSource = ds;
gridAgent.DataBind();
conn.Close();
}
}
}
And this is the code provided by my host to connect to the MySQL database.
Start
<%
Dim ConnectionString
ConnectionString="DRIVER={MySQL ODBC 5.1 Driver}; SERVER=skyhill.ipowermysql.com; PORT=3306;" &_
"DATABASE=skyhill; USER=skyhillweb; PASSWORD=*password*; OPTION=3;"
%>
' End
Upvotes: 2
Views: 8992
Reputation: 446
You can use old version of the MySQL dll for .Net, it's solve the problem.
Upvotes: 0
Reputation: 1900
It doesn't like the 'Driver' parameter of the connection string your host provided. Try this in your web.config, adapted from the mysql connector docs.
<add name="mySQLconn" connectionString="Server=skyhill.ipowermysql.com;Database=skyhill;Uid=skyhillweb;Pwd=yourpassword;" providerName="MySql.Data.MySqlClient"/>
Upvotes: 0