hawk1ns Posted July 3, 2003 Posted July 3, 2003 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 Quote
Martin Posted July 4, 2003 Posted July 4, 2003 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: <%@ 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. :) Quote
hawk1ns Posted July 6, 2003 Author Posted July 6, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.