mySQL connection string RRS feed

  • Question

  • User2126317645 posted
    Hi. I just want to know how to connect to a mySQL server from an ASP.NET page. Here are the informations I have: Host: mysql.mydns.com Port: 3306 UserID : myID Password : myPassword Database Name : myDB Wich connection string should I use? Is there anoyone who can help me?
    Friday, August 23, 2002 9:28 AM

All replies

  • User-169519270 posted
    Do You use a managed provider like dbProvider? If! you use dbProvider (I use the Personal version) do like this (can recomend it, works like a glance): '## -- Connection string to a mySQL Database -- Dim ConnectionString As String = "Data Source=localhost;Database=DBNAME;User ID=USERNAME;Password=PASSWORD" '## -- sql-query to run -- Dim CommandText As String = "select UserID, UserName from Users" '## -- creates a connnection-object to a mySQL Database -- Dim myConnection As New MySqlConnection(ConnectionString)
    Friday, August 23, 2002 3:38 PM
  • User-1764271457 posted
    I also have a major problem in getting this to work. After going through almost all threads on this forum, seeking on google etc etc I have still not found any CONCRETE information on how to connect. What Im asking for is a codeexample that... - Does not require any unnecessary 3rd party components, since my clients install my application on different servers it must be somewhat independent. - For the same reason as above I am not interested in using DSN All I want is some code that connects to mySQL and then allows me to perform common SQL-commands with EASE and without going in to 100000000 lines of code.
    Saturday, February 28, 2004 8:56 AM
  • User1371357615 posted
    If you're using C#.NET you can use something similar to this to get it to work for you. It uses the ODBC connector built in to .NET 1.1(ie. It won't work on 1.0 w/out the add-in), which is a little on the slow side if you've got a ton of records. <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.Odbc" %> <script runat="server"> private const string ConnStr = "Driver={MySQL ODBC 3.51 Driver};" + "Server=mysql.mydns.com:3306;Database=myDB;uid=myID;pwd=myPassword;option=3"; protected override void OnInit(EventArgs e) { base.OnInit(e); using(OdbcConnection con = new OdbcConnection(ConnStr)) using(OdbcCommand cmd = new OdbcCommand("SELECT * FROM myTable", con)) { con.Open(); newslist.DataSource = cmd.ExecuteReader( CommandBehavior.CloseConnection | CommandBehavior.SingleResult); newslist.DataBind(); } } </script> You should be able to modify this to get it to work... You could also dynamically build the SQL string before creating the new OdbcCommand... Is this what you're looking for? --Zen
    Saturday, February 28, 2004 2:21 PM
  • User-1764271457 posted
    Any example in VB.NET? Is it possible to work with connections like in ASP 3.0 where I put the connection in a seperate file which I included via SSI on the other pages? You know, after that you just eg.. users = connection.execute("SELECT * FROM users LIMIT 0,3") Do until users.EOF response.write (users("name")) users.movenext loop connection.close set connection = nothing ??
    Sunday, February 29, 2004 6:17 AM
  • User1668022544 posted
    You could always use a File DSN as well. To prevent using a system DSN.: OdbcConnection Database = new OdbcConnection("Provider=MSDASQL.1;FILEDSN=" + @"C:\blabla\file.dsn"); Database.Open(); OdbcCommand cmdSelect = new OdbcCommand("SELECT * FROM aTable", Database); OdbcDataReader rsRecords = cmdSelect.ExecuteReader(); while(rsRecords.Read()) { Console.WriteLine(rsRecords.GetInt32(0)); } rsRecords.Close(); Database.Close(); where file.dsn is a text file with: [ODBC] DRIVER=MySQL ODBC 3.51 Driver UID=zosa STMT= OPTION= PORT= PASSWORD=xxxxxxxx SERVER=localhost DATABASE=zosa DESC=
    Sunday, February 29, 2004 11:57 AM
  • User-1764271457 posted
    Hehe still looking for VB.NET ;) :D
    Sunday, February 29, 2004 3:02 PM
  • User1668022544 posted
    Can't re-write that for you, sorry, don't know the syntax of VB.Net Should be fairly easy to you thou if you know the syntax? After all, everything is based on classes from the framework, and they have the same names in C# and VB.NET I find myself rewriting VB.NET code to a C# syntax sometimes when checking samples :)
    Sunday, February 29, 2004 3:14 PM
  • User-1764271457 posted
    Is there any way to use a C# connectionstring and then call it to VB.NET? I know you can't use the two languages on the same page, but still, can I make it as a class and then include it in my VB.NET page?
    Monday, March 1, 2004 6:20 AM
  • User1371357615 posted
    Hmm... that's a good question. I've never tried it actually. I try to stick to one language throughout the whole site when I'm designing. As for a VB.NET conversion of the script above, I kinda wish I had one. I tried to reconfigure it to make it work with VB.NET, to no avail, so, since I had just started this project, I just switched the whole project to C#.NET. Theoretically though, you should be able to import a C#.NET page into a VB.NET Page and make it work... I'd have to know a little more about what you're trying to accomplish though. --Zen
    Monday, March 1, 2004 10:47 AM
  • User-1764271457 posted
    All im trying to do is to get a connection to mysql, but it won't work :P You know, just to do simple tasks like selecting, inserting, deleting etc. It would be really odd if there wasn't any way to connect.
    Monday, March 1, 2004 1:30 PM
  • User-1996987520 posted
    Does this help? C# to VB.NET Translator
    Monday, March 1, 2004 8:31 PM
  • User2024069563 posted
    This works for me... (after mysql 3.51 drivers have been installed) <%@ Page Language="VB" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.Odbc" %> <script runat="server"> Sub Page_Load(Sender As Object, E As EventArgs) ' TODO: Update the ConnectionString and CommandText values for your application Dim ConnectionString As String = "DRIVER={MySQL ODBC 3.51 Driver};" _ & "SERVER=Server;" _ & "DATABASE=CallerID;" _ & "UID=root;" _ & "PWD=password01;" _ & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384 Dim CommandText As String = "select * from calls" Dim myConnection As New OdbcConnection(ConnectionString) Dim myCommand As New ODBCCommand(CommandText, myConnection) myConnection.Open() DataGrid1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection) DataGrid1.DataBind() End Sub </script> <body style="FONT-FAMILY: arial">

    Simple Data Report

    <form runat="server"> <asp:datagrid id="DataGrid1" runat="server" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" ForeColor="Black" EnableViewState="False"> <HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C"></HeaderStyle> <ItemStyle backcolor="#DEDFDE"></ItemStyle> </asp:datagrid> </form>
    Saturday, March 13, 2004 10:19 AM
  • User-952248826 posted

    This link can help you.


    Saturday, December 1, 2007 1:44 AM
  • User1623436211 posted

    Refer to this link.




    Thursday, May 14, 2009 8:46 AM