connection to a mysql database on a server

hawk1ns

Active member
Joined
Jun 10, 2003
Messages
37
Hello guys .

I have a mysql database on a server , i need to know how to access this..

1st it says "select or enter a server name" .... what do i put here? is it just the domain name or is there something else i need to add to this ? does it need to be a url to a section of webspace that handles the mysql ? like localhost or something ?

2nd it also asks for a user and password ? is this going to be the same as the FTP user/pass or is this the database user/password ?

3rd can i assume if i have the above details correct when i choose "select the database on the server" i should get a list of mysql databases available ?

I realise i am probably asking very simple questions but its got me stuck :)

Regards
Carl
 
I can recommend http://www.stardeveloper.com/articles/display.html?article=2003052201&page=1 as a great starting place for connecting to MySQL servers, although this mainly deals with setting up MySQL - read page 9 onwards.

Issues you may experience when trying to connect to MySQL databases mostly arise from imports to the System.Data.ODBC class, which I have not resolved so I use Microsoft.Data.ODBC. Ignoring this complication you can use:

Code:
<%@ Page Language="C#" AutoEventWireup="False"
  EnableSessionState="False" EnableViewState="False" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>

<script runat="server">
  private const string ConnStr = "Driver={MySQL ODBC 3.51 Driver};" +
    "Server=localhost;Database=test;uid=root;pwd=yourpassword;option=3";

  protected override void OnInit(EventArgs e)
  {
    base.OnInit(e);

    using(OdbcConnection con = new OdbcConnection(ConnStr))
    using(OdbcCommand cmd = new OdbcCommand("SELECT * FROM Names", con))
    {
      con.Open();
      dgrAllNames.DataSource = cmd.ExecuteReader(
        CommandBehavior.CloseConnection | 
        CommandBehavior.SingleResult);
      dgrAllNames.DataBind();
    }
  }
</script>

<html>
<head>
  <title>Displaying Records from MySQL Names table</title>
  <style>
  body { font: 100% Verdana; }
  </style>
</head>
<body>

<p align="center">All records in the Names table:</p>

<asp:DataGrid ID="dgrAllNames" HorizontalAlign="Center"
	CellPadding="3" Runat="server" />

</body>
</html>

But that will need configuring ;)

Now, to answer your specific questions :p:

1.) Server address and port:

eg: 127.0.0.1 Port: 1234

2.) User password is of the database itself.

eg: username: root password: whatever

3.) Yes :)

Hope this helps a little. :)
 
thanks for help here :)

Just a quick question then :)

I want to create a program that runs on my pc , i guess i am talking about a standard windows application here..

i want to display a set of text boxes or a dbgrid containing the databases information..

the database is situated on a server , so i want the program to go off using internet connection and retrieve the information then display ..

In the above example i see html code , can i assume this example is for a web based program ?

if so how would you suggest i go about what i wanted ?

i have a database i have been trying to access at http://www.bon-jovi-rock-gods.com
in the database source i entered bon-jovi-rock-gods.com
then i entered the user and password for this database
i tried to test connection but get an error ..

test connection failedbecause of an error initializing provider.... invalid connection ?

would you have any suggestions ?

Regards
Carl
 
Back
Top