Quantcast
Channel: Oracle, MySQL, Sybase, Informix and other databases
Viewing all articles
Browse latest Browse all 1350

Connect a Web Forms Application to a MySQL DB hosted on Godaddy

$
0
0

Hello all,

I have built a small web forms application in VS Express 2013 Web to connect to a MySQL DB and process some data. The MySQL DB is hosted on our godaddy shared hosting server as well as the website. I have no issues connecting to the DB from my local machine by using a reference to the MySql.Data.dll but when I publish the web forms app and add it to my website on godaddy I continually receive the "CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?)" compilation error on the using directive "using MySql.Data.MySqlClient;".

When I publish the project in VS 2013 I make sure that the "Copy Local" property for the MySql.Data.dll file is set to true and when it finishes publishing that file does exist in the "bin" folder of the project.

My godaddy shared server is running .NET 4.0/4.5, I have complied the VS project in .NET 4.0 and the MySql.Data.dll file is also for .NET 4.0

Right now I am getting the connection string from a class in the web forms app .cs file for testing purposes.

I have posted my code below, any and all help is appreciated.

Aspx.cs File:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Collections;
using MySql.Data.MySqlClient;

namespace DB_Connect_Application
{
    public partial class just_connect : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void connectButtonClick(object sender, EventArgs e)
        {
            DBConnection db = new DBConnection();
            String connected = db.connectToDB();
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Alert", "alert('" + connected + "');", true);
        }
    }
    public class DBConnection
    {
        private String connection_string = null;
        private String server = "server.db.someresources.com;";
        private String database = "databasename;";
        private String username = "dbusername;";
        private String password = "dbpassword;";

        //Defualt Constructor
        public DBConnection()
        {
        }

        public String getConnectionString()
        {
            connection_string = "SERVER=" + server + " DATABASE=" + database + " USER=" + username + " PASSWORD=" + password;
            return connection_string;
        }

        public String connectToDB()
        {
            String connstring = getConnectionString();
            MySqlConnection con = new MySqlConnection(connstring);
            try
            {
                con.Open();
                return "Connected";
            }
            catch (MySqlException ex)
            {
                return "Did not connect";
            }
        }
    }
}

Aspx File:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="just_connect.aspx.cs" Inherits="DB_Connect_Application.just_connect" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server"><div><br /><asp:Button Text="Connect" OnClick="connectButtonClick" runat="server" /><br /></div></form></body></html>

Thank you.


Viewing all articles
Browse latest Browse all 1350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>