locked
MySQL and ASP.NET MVC - I hope I made a good choice. RRS feed

  • Question

  • User-1785554541 posted

    Hello Everyone.

    At university, we are currently working on a group project. The project consists of a Java Application and a Website. Both of these will be grabbing Data from a Database.

    The Database team decided to go with MySQL for the implementation of the Database. The design and building of the website was left to me.

    The Database people were pressuring me to use PHP to run the website, but over the past month I feel that my skills are better in ASP.NET than they are in PHP.

    I have worked with Databases in ASP.NET before, but that always was SQL Server 2008, where I would right-click on the App-Data folder and add a new SQL Database .. etc

    This time though it is different:

    1. The database is MySQL
    2. It is hosted on a server somewhere

    How do I go about working with that MySQL Database in Visual Studio 2010 ? I hope I have made the right choice in terms of sticking to ASP.NET for this.

    I would greatly appreciate any help.

    Thank You.

    Monday, January 24, 2011 10:10 PM

Answers

  • User2019981500 posted

    Hi,

    In VS2010 There is option menuitem where you can see:

    Text Editor\C#\Advanced -> Underline errors in the editor and Show live semantic errors

    If you don't enable the second option then you won't see any errors until you compile.you need to uncheck or check as per your liking.


    Next ,I have not used MVC with MYSQL But I assure you that there is no logic in saying that "you can't get MySQL to work with ASP.NET MVC"

    Yes you can see here how to work with MVC-MYSQL


    .net - Asp.net MVC with mysql - Stack Overflow


    Regards

    shabir


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 26, 2011 1:13 AM

All replies

  • User2019981500 posted

    Hi,

    I do agree that you have made good choice because now time has moved so fast that there is no way to compare PHP with ASP.NET because ASP.NET is now such a productive,reliable and extensible technology where you can do wonders.Don't consider me religious about asp.net.I have observed most of the systems are now switching technology choice from PHP to ASP.NET.

    Well ,second thing is connecting to MySQL is not big deal,let database be anywhere.Your Connection string will look like

     strConn = "DRIVER={MySQL ODBC 3.51 Driver};server=82.103.138.122:3306;DATABASE=database;" & _
            "USER=username;PASSWORD=password; OPTION=3;"

    See Connection strings

    MySQL Connection Strings

    if you don’t know mySQL, MySQL is an open-source DataBase server. Being that it’s open-source, it’s also free.To be able to use MySQL, there are a couple of downloads that must be done:

    1. MySQL Itself
    2. MySQL ODBC Driver

    The Database Server (MySQL), itself can be downloaded here: http://dev.mysql.com/downloads/mysql/4.0.html

    The Driver (for Windows) can be downloaded here:
    http://dev.mysql.com/downloads/connector/odbc/3.51.html

    Now, once this is all set up – guess what – you have no data. If you want, the above installation page will also help you get started creating databases, tables and fields for your sample data. But, if you want a much quicker way to populate your database server, so you can get started, AugustWind Software has user interface for MySQL called Data Management Toolkit. Check it out here

    Now – the part you actually came here for – - the easy part!

    On other parts of this site, you’ve seen many samples, using MS Access and SQL Server. As you might have noticed, there are only three major differences in using these.

    1. Namespaces used
    2. Connection String
    3. Prefix to data classes (like: OleDbDataAdapter vs. SQLDataAdapter, specific to the Imported Namespaces

    For MySQL, the driver which you downloaded (above), is an ODBC Driver, therefore, numbers 1 and two in the above list use ‘ODBC’:

    <%@ Import Namespace="System.Data.ODBC" %>

    see next because above tutorial continuation  goes below..

    http://www.aspnet101.com/2007/09/using-mysql-with-asp-net-2/


    Regards

    shabir


    Monday, January 24, 2011 10:41 PM
  • User-1785554541 posted

    Thank You Very Much Shabir.

    Regarding the two downloads for MySQL. I already have WAMP installed on my Windows 7 PC.

    Would I still have to download them two things ? Cause as far as I know WAMP installs everything one needs for working with MySQL !

    I await your response.

    Thank You.

    Monday, January 24, 2011 10:54 PM
  • User2019981500 posted

    Hi,

    Great WAMP is complete and The WAMP stack provides developers with the four key elements of a Web server:  an OS,Database, Web server and Web scripting software.So,no need to install anything else

    All the best

    Regards

    shabir

    Tuesday, January 25, 2011 12:15 AM
  • User-1785554541 posted

    Thanks Shabir.

    I did some google searching on how I would connect to MySQL in ASP.NET (C#) and I got some code. When I insert the code, I get many errors. I am placing the code in the UpdateAccount Model.

    public class UpdateAccountModel
        {
            // TODO: Update the ConnectionString and CommandText values for your application
            string ConnectionString = @"driver={MySQL ODBC 3.51 Driver};server=localhost;database=dbname;uid=username;pwd=password;";
            string CommandText = "select * from tablename";
        
            OdbcConnection myConnection = new OdbcConnection(ConnectionString);
            OdbcCommand myCommand = new OdbcCommand(CommandText, myConnection);
        
            myConnection.Open();
        
            DataGrid1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            DataGrid1.DataBind();
        
            // close the connection
            myConnection.Close();
    
        }


     

    The errors are in the form of red underlines in Visual Studio 2010. I get the errors even though I have added the { using System.Data.Odbc; }

    I would greatly appreciate any help wit this.

    Thank You.

    Tuesday, January 25, 2011 3:27 PM
  • User-1785554541 posted

    Many Forums are saying you can't get MySQL to work with ASP.NET MVC !!!!!!!!!!

    Is this True ? :( 

    Tuesday, January 25, 2011 3:40 PM
  • User2019981500 posted

    Hi,

    In VS2010 There is option menuitem where you can see:

    Text Editor\C#\Advanced -> Underline errors in the editor and Show live semantic errors

    If you don't enable the second option then you won't see any errors until you compile.you need to uncheck or check as per your liking.


    Next ,I have not used MVC with MYSQL But I assure you that there is no logic in saying that "you can't get MySQL to work with ASP.NET MVC"

    Yes you can see here how to work with MVC-MYSQL


    .net - Asp.net MVC with mysql - Stack Overflow


    Regards

    shabir


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 26, 2011 1:13 AM