Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2008
    Posts
    16

    Question Unanswered: connect to mysql via VB

    hello first i hope i am posting in the right place and apologise if i am not.

    i host a webserver on my home machine and everything works fine, can connect to my own site from localhost and from the internet perfectly however i have another problem, i hope someone here can help me.

    ive been learning VB and have created a small simple windows form app with a single button what when pressed will connect to my sql db eccept it wont connect [] i get a error message which can be seen here www.dchubad.com/error.jpg i cant figure it out.
    i have asked on the MSDN forums and was told that maybe someone here might be able to help with just the connection probs to the server. any help would be much appreciated. thank you

    i have added also my full VB code below (if this might also help) maybe someone could see what i am doing wrong with my connection string. thanks

    Code:
    Imports System.Data.SqlClient
    
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim myConnectionString As String = "server=127.0.0.1;uid=server;pwd=;database=dcphl;"
            Dim myConnection As New SqlConnection(myConnectionString)
            Dim myCommand As SqlCommand = myConnection.CreateCommand()
            Try
                myConnection.Open()
                MsgBox("<Bot> SQL LOGIN SUCCESSFUL!")
            Catch ex As SqlException
                MsgBox(ex.Message)
            Finally
                myConnection.Close()
            End Try
        End Sub
    End Class
    i just cant figure out what i am doing wrong, any support would be much appreciated, thank you

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    are you trying to connect to a MySQL db or a SQL server DB?

    if MySQL then you almost certainlyhave to go through the ODBC connector

  3. #3
    Join Date
    Mar 2008
    Posts
    16
    im not sure i have little knowledge about mysql servers.
    basically i run a small website on my home computer which all works perfect and i have added a new database called dcphl which ive added some temp stuff in so its not empty.
    all of my web applications such as mysql apache php etc was installed by an all in one programmed called xampp. i was trying to use a simple application written in VB to connect to the database.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so you are trying to connect to MySQL then?

    your connection string is wrong
    the code you have us trying toi connect to SQL server, as the message tells you. You need to download the appropriate ODBC driver for whatever VB you are using, then use the connections tring as shown the helpfile for that ODBC driver, or the page where you download the ODBC driver from.

  5. #5
    Join Date
    Mar 2008
    Posts
    16
    ok thanks i will give that a try now thanks

  6. #6
    Join Date
    Mar 2008
    Posts
    16
    you were right it works now, many thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •