I know this might sound like questions you’ve heard before, but I could really use some help or rather clarification.I cannot connect to my MySQL database.I have tried so many different ways and keep getting different errors every time I change something!My latest codes and errors are at the bottom of this post. I have been reading every forum and help topic on this that I can find and I am now completely confused! Please Help!
The following is what I am 100% sure of:
·The database is using GoDaddy shared hosting which uses phpMyAdmin to administrate it.
·When I set up my database, I told it to allow remote connections and assign a DSN.
·My GoDaddy Windows Hosting account uses IIS 6.0 and ASP.Net runtime version 2.0/3.0/3.5
·The MySQL server uses version:
5.0.67.d7-ourdelta-log
·GoDaddy told me that they use the ODBC 3.51 as the default on my server.
·When setting up the database I chose to use the MyISAM data engine instead of InnoDB.
·I have both Microsoft Expression Web 2 and C# Express at my disposal.
·C# Express doesn’t seem to want to connect to anything other than a locally hosted database
·I have IIS 7 installed on my Windows Vista Home Premium machine.
·IIS Metabase and IIS 6 configuration compatibility is enabled on my machine as well.
·I have MySQL Connector/NET 1.0.10.1 installed on my machine.
·I have MySQL Connector/ODBC 3.51 installed on my machine.
·I’d like to stay with the languages: ASP.NET 3.5 and C#.The MySQL server supposedly supports an ADO connection.
If someone can help with an ADO solution to my problem I will attempt to learn that language too!I will use whatever connector I can get to work!! ODBC, .Net, or whatever!
·My web config file only has error logging enabled in it.No other commands!
·I created a bin directory and put both assemblyinfo.cs and MySQL.Data.dll into it.
This is the very simple connection I am initially trying to make (I created this with Expression Web 2):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
These are the connection strings, copied from the suggested configuration file inside my GoDaddy account:
ODBC 3.51:
DRIVER={MySQL ODBC 3.51 Driver}; SERVER=LHYPartsDB.db.#######.hostedresource.com; PORT=3306; DATABASE=LHYPartsDB; USER=LHYPartsDB; PASSWORD='your password'; OPTION=0;
OLE DB, OleDbConnection (.NET):
Provider=MySQLProv; Data Source=LHYPartsDB.db.#######.hostedresource.com; Initial Catalog=LHYPartsDB; User ID=LHYPartsDB; Password='your password';
Connector/Net 1.0 (.NET):
Server=LHYPartsDB.db.#######.hostedresource.com; Port=3306; Database=LHYPartsDB; Uid=LHYPartsDB; Pwd='your password';This
is the error I get when I run the above page:Keyword not supported: 'driver'.Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated
in the code.
Exception Details:
System.ArgumentException: Keyword not supported: 'driver'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and
location of the exception can be identified using the exception stack trace below.
<div class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; TEXT-ALIGN: center" align=center></div>Version Information: Microsoft .NET Framework
Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433Thanks
in advance for any help you can give!
mysqlasp.netConnectionStringdatabaseConnection with MySQL Database from ASP.NET 2.0Godaddydbconnect to MySQL on remote PCmysql.dllodbcmysql 5.0MySQL connector driverconnect to MySQL on serverweb.configasp.net goaddy mysqlconnectionn string.net 3.5mysql connectorconnectormysql and asp.net
then you can use the code below in your database class:
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.Hosting;
using MySql.Data.MySqlClient;
public class database
{
private readonly MySqlConnection conn = new MySqlConnection();
private MySqlDataAdapter myadapter = new MySqlDataAdapter();
private MySqlCommand myCommand = new MySqlCommand();
private MySqlDataReader mydata;
private readonly string dbconn = ConfigurationManager.AppSettings["dbconn"];
// your procedures here
// to open use:
conn.ConnectionString = dbconn;
conn.Open();
}
the connection string you used is for classic ASP, in asp.net you use the mysqldata.mysqlcLIENT you can add this to your project by putting this into your bin directory, then make a reference to the DLL in your bin folder.
OK, I have attempted both solutions offered and I am still confused and can't connect. I have set Expression Web aside and am using the C# Express 2008 program. This program, however, does not seem to recognize a connection to a remote database. The idea
behind this project is to have a web page that displays a listing of the motorcycle tires that we would like to put on special sale. That purpose is why I started in Expression Web. In my dreams, I would like the web page user to be able to sort the information
by size, location (front or rear tire), or manufacturer. Also, I would like to make it so that tires with a quantity of zero are not displayed. Because I want my parts department to be able to change the quantity (and only the quantities) I would like to
create a GUI. It does not need to be a web page, but could be as long as they have to log on. The GUI could also be a program installed on a single computer in the parts department where it would not be a requirement to log on.
Because the data would need to be displayed on a web page I decided I probably should use a database that came with my web hosting. I chose to go with MySQL because it is so popular and I am allowed 10 of them as opposed to 1 Access db or 1 SQL db. Maybe
I went wrong here.
Anyway, I know I first need the database set up, then the connection, then a page to display it. My database is complete with 15 fields and 27 rows. My primary key is my part_number field. When I use the following query from inside phpMyAdmin, it works
perfectly.
So, since I am using C# Express I now have multiple pages and am not sure that my connection string reference is right for what is in my config file.
I am also not sure since the program doesn't seem to acknowledge the connection, how do I bind data to it, or will that ever be possible? I'm thinking that I am not calling the connection properly.
And... Microsoft Expression Web supports asp.net and C# and even suggests that you create your C# code in an editor designed especially for it, so I should be able to use C# Express created files with expression web if I need to. I also downloaded Visual
Studio Express 2008 last night. Not sure if it will help.
The following is the code I currently have in C# Express. There is only one form with a gridview dropped onto it.
Program.cs:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Windows.Forms; 5 using System.Configuration; 6 using System.Data; 7 using System.Data.OleDb; 8 using System.Web; 9 using System.Web.Hosting; 10 using MySql.Data.MySqlClient; 11 12 13 namespace DiscountedTires 14 { 15 static class Program 16 { 17 /// <summary> 18 /// The main entry point for the application. 19 /// </summary> 20 [STAThread] 21 static void Main() 22 { 23 Application.EnableVisualStyles(); 24 Application.SetCompatibleTextRenderingDefault(false); 25 Application.Run(new Form1()); 26 } 27 } 28 public class database 29 { 30 private readonly MySqlConnection conn =
new MySqlConnection(); 31 private MySqlDataAdapter myadapter =
new MySqlDataAdapter(); 32 private MySqlCommand myCommand =
new MySqlCommand(); 33 private MySqlDataReader mydata; 34 35 private readonly string dbconn = ConfigurationManager.AppSettings["dbconn"]; 36 37 // your procedures here 38 // to open use: 39 40 string commandStr = "SELECT `part_number` , `mfg` , `model_name` , `model_number` , `size` , `construction` , `tube` , `load_rating_lbs` , `speed_rating` , `sidewall_style` , `location` , `msrp` , `sale_price`
, `note` 41 FROM `Tires` 42 ORDER BY `size` ASC 43 LIMIT 0 , 30 44 45 conn.ConnectionString = dbconn; 46 conn.Open(); 47 MySqlDataReader rea=cmd.ExecuteReader() 48 } 49 }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DiscountedTires
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
Form1.Designer.cs:
namespace DiscountedTires
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
// this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(21, 48);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(240, 150);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
//
// Form1
// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 264);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3074
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------namespace DiscountedTires.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DiscountedTires.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
Settings.Designer.cs:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3074
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------namespace DiscountedTires.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database1.mdf;Integrate" +
"d Security=True;User Instance=True")]
public string Database1ConnectionString {
get {
return ((string)(this["Database1ConnectionString"]));
}
}
}
}
By the way, I know that the connection string in this last file is wrong, but I'm not sure if it matters.
Because your using the less secure remote connection option. Its exactly the same on your dev pc as it is in the hosting environment. If it works on pc it works in production
(remote enabled). You get it working on your pc. The dotnet connector works. Its a c# project dll. I actually compiled mine but eventually went with the signed version I downloaded from mysql.
you will know if the reference is wrong as you will be able to view an error, plus the vs coder will show an error too
but what is your error, then maybe at least we can have an idea whats going on.
as for DB if you are new to mysql + c# then you may be better with sql express and the one database you get on the host
as you will find more tutorials/books and code for this, plus when it comes to stored procedures, there is a difference with mysql and mssql.
just let me know the error is, but i suspect that maybe the host provider does not let you connect from home, and only from there servers
in this case you need a local copy of the mysql database (mysql essentials package) and then you can simply export your database, for import onto the host.
Otherwise the grid will not generate the columns required when running.
Also, you don't need the "<%@ Import Namespace = "MySql.Data.MySqlClient" %>" as this is to use the mySql .Net connector, which you are not using, you are using ODBC; so this line can dissapear, it doesn't hurt to keep it but
it's really not doing anything.
This is also not required as it's part of the mySql .Net connector:
I created a bin directory and put both assemblyinfo.cs and MySQL.Data.dll into it.
Tryit out and let me know if it worked.
Regards,
AngelX
Marked as answer by LHYWebDesigner on Apr 01, 2009 03:32 PM
LHYWebDesign...
Member
35 Points
33 Posts
Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 29, 2009 10:17 PM|LINK
I know this might sound like questions you’ve heard before, but I could really use some help or rather clarification. I cannot connect to my MySQL database. I have tried so many different ways and keep getting different errors every time I change something! My latest codes and errors are at the bottom of this post. I have been reading every forum and help topic on this that I can find and I am now completely confused! Please Help!
The following is what I am 100% sure of:· The database is using GoDaddy shared hosting which uses phpMyAdmin to administrate it.
· When I set up my database, I told it to allow remote connections and assign a DSN.
· My GoDaddy Windows Hosting account uses IIS 6.0 and ASP.Net runtime version 2.0/3.0/3.5
· The MySQL server uses version: 5.0.67.d7-ourdelta-log
· GoDaddy told me that they use the ODBC 3.51 as the default on my server.
· When setting up the database I chose to use the MyISAM data engine instead of InnoDB.
· I have both Microsoft Expression Web 2 and C# Express at my disposal.
· C# Express doesn’t seem to want to connect to anything other than a locally hosted database
· I have IIS 7 installed on my Windows Vista Home Premium machine.
· IIS Metabase and IIS 6 configuration compatibility is enabled on my machine as well.
· I have MySQL Connector/NET 1.0.10.1 installed on my machine.
· I have MySQL Connector/ODBC 3.51 installed on my machine.
· I’d like to stay with the languages: ASP.NET 3.5 and C#. The MySQL server supposedly supports an ADO connection. If someone can help with an ADO solution to my problem I will attempt to learn that language too! I will use whatever connector I can get to work!! ODBC, .Net, or whatever!
· My web config file only has error logging enabled in it. No other commands!
· I created a bin directory and put both assemblyinfo.cs and MySQL.Data.dll into it.
This is the very simple connection I am initially trying to make (I created this with Expression Web 2):<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>
<%@ Import Namespace = "System.Data.Odbc" %>
<%@ Assembly Name="System.Data" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>LHY Discount Tires</title>
</head>
<body>
<form id="form1" runat="server">
<div id="TiresGridView">
<asp:Gridview
ID="grdTires"
DataSourceID="srcTires"
runat="server" />
<asp:SqlDataSource
id="srcTires"
SelectCommand="SELECT * FROM Tires"
ConnectionString="DRIVER={MySQL ODBC 3.51 Driver}; SERVER=LHYPartsDB.db.#######.hostedresource.com; PORT=3306; DATABASE=LHYPartsDB; USER=LHYPartsDB; PASSWORD='my password'; OPTION=0; "
runat="server" />
</div>
</form>
</body>
</html>
These are the connection strings, copied from the suggested configuration file inside my GoDaddy account: ODBC 3.51: DRIVER={MySQL ODBC 3.51 Driver}; SERVER=LHYPartsDB.db.#######.hostedresource.com; PORT=3306; DATABASE=LHYPartsDB; USER=LHYPartsDB; PASSWORD='your password'; OPTION=0; OLE DB, OleDbConnection (.NET): Provider=MySQLProv; Data Source=LHYPartsDB.db.#######.hostedresource.com; Initial Catalog=LHYPartsDB; User ID=LHYPartsDB; Password='your password'; Connector/Net 1.0 (.NET): Server=LHYPartsDB.db.#######.hostedresource.com; Port=3306; Database=LHYPartsDB; Uid=LHYPartsDB; Pwd='your password'; This is the error I get when I run the above page:Keyword not supported: 'driver'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.ArgumentException: Keyword not supported: 'driver'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: Keyword not supported: 'driver'.] System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +1481474 System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +102 System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +52 System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24 System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +125 System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +56 System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +138 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69 System.Web.UI.Control.EnsureChildControls() +87 System.Web.UI.Control.PreRenderRecursiveInternal() +50 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041</div>Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433 Thanks in advance for any help you can give!
mysql asp.net ConnectionString database Connection with MySQL Database from ASP.NET 2.0 Godaddy db connect to MySQL on remote PC mysql.dll odbc mysql 5.0 MySQL connector driver connect to MySQL on server web.config asp.net goaddy mysql connectionn string .net 3.5 mysql connector connector mysql and asp.net
adefwebserve...
Contributor
5912 Points
1207 Posts
MVP
Re: Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 30, 2009 01:57 AM|LINK
I don't know if you can use a SQL Data Source control with MySQL. This example should work for you:
http://dotnetnuke.adefwebserver.com/MySQL/MySql5sample/tabid/289/Default.aspx
Open Light Group
LightSwitchHelpWebsite.com | ADefWebserver.com
minus4
Member
151 Points
71 Posts
Re: Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 30, 2009 08:45 AM|LINK
you want something like this:
inside web.config: add a appsettings section
then you can use the code below in your database class:
LHYWebDesign...
Member
35 Points
33 Posts
Re: Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 31, 2009 12:55 AM|LINK
OK, I have attempted both solutions offered and I am still confused and can't connect. I have set Expression Web aside and am using the C# Express 2008 program. This program, however, does not seem to recognize a connection to a remote database. The idea behind this project is to have a web page that displays a listing of the motorcycle tires that we would like to put on special sale. That purpose is why I started in Expression Web. In my dreams, I would like the web page user to be able to sort the information by size, location (front or rear tire), or manufacturer. Also, I would like to make it so that tires with a quantity of zero are not displayed. Because I want my parts department to be able to change the quantity (and only the quantities) I would like to create a GUI. It does not need to be a web page, but could be as long as they have to log on. The GUI could also be a program installed on a single computer in the parts department where it would not be a requirement to log on.
Because the data would need to be displayed on a web page I decided I probably should use a database that came with my web hosting. I chose to go with MySQL because it is so popular and I am allowed 10 of them as opposed to 1 Access db or 1 SQL db. Maybe I went wrong here.
Anyway, I know I first need the database set up, then the connection, then a page to display it. My database is complete with 15 fields and 27 rows. My primary key is my part_number field. When I use the following query from inside phpMyAdmin, it works perfectly.
SELECT `part_number` , `mfg` , `model_name` , `model_number` , `size` , `construction` , `tube` , `load_rating_lbs` , `speed_rating` , `sidewall_style` , `location` , `msrp` , `sale_price` , `note`
FROM `Tires`
ORDER BY `size` ASC
LIMIT 0 , 30
So, since I am using C# Express I now have multiple pages and am not sure that my connection string reference is right for what is in my config file.
I am also not sure since the program doesn't seem to acknowledge the connection, how do I bind data to it, or will that ever be possible? I'm thinking that I am not calling the connection properly.
And... Microsoft Expression Web supports asp.net and C# and even suggests that you create your C# code in an editor designed especially for it, so I should be able to use C# Express created files with expression web if I need to. I also downloaded Visual Studio Express 2008 last night. Not sure if it will help.
The following is the code I currently have in C# Express. There is only one form with a gridview dropped onto it.
Program.cs:
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Windows.Forms;
5 using System.Configuration;
6 using System.Data;
7 using System.Data.OleDb;
8 using System.Web;
9 using System.Web.Hosting;
10 using MySql.Data.MySqlClient;
11
12
13 namespace DiscountedTires
14 {
15 static class Program
16 {
17 /// <summary>
18 /// The main entry point for the application.
19 /// </summary>
20 [STAThread]
21 static void Main()
22 {
23 Application.EnableVisualStyles();
24 Application.SetCompatibleTextRenderingDefault(false);
25 Application.Run(new Form1());
26 }
27 }
28 public class database
29 {
30 private readonly MySqlConnection conn = new MySqlConnection();
31 private MySqlDataAdapter myadapter = new MySqlDataAdapter();
32 private MySqlCommand myCommand = new MySqlCommand();
33 private MySqlDataReader mydata;
34
35 private readonly string dbconn = ConfigurationManager.AppSettings["dbconn"];
36
37 // your procedures here
38 // to open use:
39
40 string commandStr = "SELECT `part_number` , `mfg` , `model_name` , `model_number` , `size` , `construction` , `tube` , `load_rating_lbs` , `speed_rating` , `sidewall_style` , `location` , `msrp` , `sale_price` , `note`
41 FROM `Tires`
42 ORDER BY `size` ASC
43 LIMIT 0 , 30
44
45 conn.ConnectionString = dbconn;
46 conn.Open();
47 MySqlDataReader rea=cmd.ExecuteReader()
48 }
49 }
App.config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> </configSections> <connectionStrings> <add name="MySQLConnectionString" connectionString="server=LHYPartsDB.db.#######.hostedresource.com; user id=LHYPartsDB; password=mypassword; database=LHYPartsDB; pooling=false;" providerName="System.Data.SqlClient" /> </connectionStrings> <appSettings> <add key="mysqlconn" value="server=LHYPartsDB.db.#######.hostedresource.com;user id=LHYPartsDB;password=mypassword;persist security info=True;database=LHYPartsDB"/> </appSettings> </configuration>Form1.cs:
Form1.Designer.cs:
AssemblyInfo.cs:
Resource.Designer.cs:
Settings.Designer.cs:
By the way, I know that the connection string in this last file is wrong, but I'm not sure if it matters.
Danny117
Star
11160 Points
1932 Posts
Re: Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 31, 2009 02:41 AM|LINK
Because your using the less secure remote connection option. Its exactly the same on your dev pc as it is in the hosting environment. If it works on pc it works in production (remote enabled). You get it working on your pc. The dotnet connector works. Its a c# project dll. I actually compiled mine but eventually went with the signed version I downloaded from mysql.
Drop the mysql.data.dll in the bin folder
reference it an using it
Me on linked in
LHYWebDesign...
Member
35 Points
33 Posts
Re: Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 31, 2009 03:07 AM|LINK
It doesn't work on my development pc and I do have the mysql.data.dll in the bin folder. Am I referenceing it wrong?
minus4
Member
151 Points
71 Posts
Re: Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 31, 2009 08:09 AM|LINK
you will know if the reference is wrong as you will be able to view an error, plus the vs coder will show an error too
but what is your error, then maybe at least we can have an idea whats going on.
as for DB if you are new to mysql + c# then you may be better with sql express and the one database you get on the host
as you will find more tutorials/books and code for this, plus when it comes to stored procedures, there is a difference with mysql and mssql.
just let me know the error is, but i suspect that maybe the host provider does not let you connect from home, and only from there servers
in this case you need a local copy of the mysql database (mysql essentials package) and then you can simply export your database, for import onto the host.
dave
AngelX
Member
26 Points
2 Posts
Re: Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 31, 2009 09:18 AM|LINK
LHYWebDesigne,
There are some basic errors in your code, reason why you are getting the driver keyword error.
Your connection string:
<asp:SqlDataSource id="srcTires" SelectCommand="SELECT * FROM Tires" ConnectionString="DRIVER={MySQL ODBC 3.51 Driver}; SERVER=LHYPartsDB.db.#######.hostedresource.com; PORT=3306; DATABASE=LHYPartsDB; USER=LHYPartsDB; PASSWORD='my password'; OPTION=0; " runat="server" />What's wrong with it?
You are missing the ProvideName attribute, which tells VisualStudio what kind of connection your talking about.
How it should be:
Also there is an attribute missing in:
<asp:Gridview ID="grdTires"
DataSourceID="srcTires"
runat="server" />
It needs:
<asp:Gridview ID="grdTires"
DataSourceID="srcTires"
runat="server" AutoGenerateColumns="true" />
Otherwise the grid will not generate the columns required when running.
Also, you don't need the "<%@ Import Namespace = "MySql.Data.MySqlClient" %>" as this is to use the mySql .Net connector, which you are not using, you are using ODBC; so this line can dissapear, it doesn't hurt to keep it but it's really not doing anything.
This is also not required as it's part of the mySql .Net connector:
I created a bin directory and put both assemblyinfo.cs and MySQL.Data.dll into it.
Tryit out and let me know if it worked.
Regards,
AngelX
AngelX
Member
26 Points
2 Posts
Re: Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 31, 2009 09:33 AM|LINK
By the way, on your C# forms project, the same mistake is repeated:
App.config:
Line 7 reads: provierName="System.Data.SqlClient" SqlClients are Microsoft SQL clients, not mySql clients so this is incorrect.
Note that you are using MySql.Data.MySqlClient, so the providerName should be "MySql.Data.MySqlClient" not "System.Data.SqlClient".
AngelX
Danny117
Star
11160 Points
1932 Posts
Re: Connection to MySQL is DRIVING ME CRAZY!!!! Please Help!
Mar 31, 2009 12:43 PM|LINK
www.connectionstrings.com
<connectionStrings>
<add name="BlogEngine" connectionString="Server=server;Database=yourdatabaase;Uid=yourdatabase;Pwd=xxxx;"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
drop mysql.data.dll 5.2 whatever in your bin folder
Then have at it.
Here's my blog post on it with complete code. http://www.gosylvester.com/blog.aspx?id=24
(tip substitue imports with using)
Me on linked in