Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

MySQL And Visual Studio 2005 Connection

Options
  • 22-11-2007 1:24pm
    #1
    Registered Users Posts: 325 ✭✭


    Hi All

    I'm having a problem trying to connect a MySQL database to Visual Studio 2005.

    I've downloaded all the necessary connectors that the website told me I needed such as the MySQL Connector and the MySQl and Visual Studio Connector.


    When I open VS I go to "Connect To Database" and select the MySQL Database option.

    I'm than given a list of boxes to fill out: Server Name, Username, Password and Database Name.

    I'm having trouble with this section - In the manual it says the default server name is "Localhost" but this doesn't seem to work for me - Does anyone know how I can find out what I should put in here?

    Also is the username and password just something I'm suposed to make up so people can't edit my connection.

    I'd really appreciate it if someone could give me a hand to connect these as I really need it to continue my project.


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Where is your MySQL Server located?

    What it's asking you for is the hostname where your MySQL server is connected, and the username and password that you use to access that server.

    MySQL isn't like Access - with access, you just specify the data file to access. MySQL is a database server, so you need to know where the MySQL service is running and have a username & password for that server.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Stupid question, but I take it you have MySQL installed and running on the webserver?

    You'll probably want to put in a lot more error handling, but this should get you going.
    string sConnString = "Driver={MySQL ODBC 3.51 Driver};SERVER=DatabaseServerIP;DATABASE=Databasename;Uid=Usernamehere;Pwd=Passwordhere;"
    string sSQL = "select * from sometable";
    
    OdbcConnection objConn = new OdbcConnection();
    objConn.ConnectionString = sConnString;
    objConn.Open();
    
    OdbcCommand objCmd = new OdbcCommand();
    objCmd.Connection = objConn;
    objCmd.CommandType = CommandType.Text;
    objCmd.CommandText = sSQL;
    
    OdbcDataReader objDR;
    objDR = objCmd.ExecuteReader();	
    
    lso is the username and password just something I'm suposed to make up so people can't edit my connection.

    No, it's the details for the user on the database. Download the MySQL Administrator and MySQL Query browser and make sure you can login with the credentials you're using in your .net application.


  • Registered Users Posts: 325 ✭✭doyler442


    Cheers for the answers.

    I downloaded MySQL Administrator but I can't login with the details I'm using at all.

    The error message i'm getting is "Access denied for user 'ODBC'@localhost'"

    Any ideas?


  • Registered Users Posts: 325 ✭✭doyler442


    Its alright, after quite a bit of reading of the manual I found that the set username I was supposed to use was ROOT


    Thanks for the help - and I'm pretty sure I'll be having to ask some more questions


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    doyler442 wrote: »
    Its alright, after quite a bit of reading of the manual I found that the set username I was supposed to use was ROOT


    Thanks for the help - and I'm pretty sure I'll be having to ask some more questions

    Cool - by the way, the code I posted doesn't use the MySQL data class, which is probably more suitable. I think the syntax is pretty much the same as the Odbc one, but I don't have that code to hand at the moment. I can post it from home if needs be.


  • Advertisement
  • Registered Users Posts: 1,045 ✭✭✭Bluefrog


    While I have some MySQL gurus here I'm gonna hijack this tread to get some feedback.

    I have an ASP.NET site hosted on Hosting365 and it uses data from a MySQL server also with hosting365.

    When the site went up all was fine for a year or so. Then all of sudden, random errors ("lost connection to the database during query") started happening. I'm using the MyODBC driver (3.51) to connect to the database and am closing all connections after running querys loading mainly datareaders. The errors as I say are random and not specific to any particular queries.

    Anyone else seen this behaviour?


Advertisement