Results 1 to 5 of 5

Thread: connect to mysql from vb.net standard thru code

  1. #1

    Thread Starter
    Addicted Member craigreilly's Avatar
    Join Date
    Jul 2004
    Location
    Scottsdale, AZ
    Posts
    188

    Resolved connect to mysql from vb.net standard thru code

    I have tried to figure this out all day...
    I have read that it is possible to connect to mysql in vb.net standard thru code.
    I have not been able to figure this out...

    please post some usable code...
    server=(localhost)
    database="mysql"
    table="employees"
    no username, no password
    Last edited by craigreilly; Oct 8th, 2004 at 06:22 PM.

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    maybe
    VB Code:
    1. imports microsoft.data.odbc
    2. dim cn as odbcconnection()
    3. sub connect()
    4.   cn.connectionstring="driver={[i]your_driver[/i]};database=[i]db_name[/i];"
    5.   cn.open()
    6.   . . .
    7.   cn.close()
    8. end sub
    in my case i have mysql odbc 3.51 driver as my driver. hope this helps, if not, sorry... and oh... add microsoft.data.odbc.dll as a reference.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Download the MySQLDirect .NET data provider from this URL:

    http://crlab.com/mysqlnet/download.html


    A connection string would look like:

    VB Code:
    1. Imports CoreLab.MySql
    2.  
    3. Dim oMySqlConn As MySqlConnection = New MySqlConnection()
    4. oMySqlConn.ConnectionString = "User ID=myUsername;" & _
    5.                               "Password=myPassword;" & _
    6.                               "Host=localhost;" & _
    7.                               "Port=3306;" & _
    8.                               "Database=myDatabaseName;" & _
    9.                               "Direct=true;" & _
    10.                               "Protocol=TCP;" & _
    11.                               "Compress=false;" & _
    12.                               "Pooling=true;" & _
    13.                               "Min Pool Size=0;" & _
    14.                               "Max Pool Size=100;" & _
    15.                               "Connection Lifetime=0"

  4. #4

    Thread Starter
    Addicted Member craigreilly's Avatar
    Join Date
    Jul 2004
    Location
    Scottsdale, AZ
    Posts
    188
    http://www.sevenobjects.com/clientSamples.aspx

    This place has a mysqlclient to download. Free for commercial and non-commercial use. It would have to be loaded on the client machine - but is a DSN-less connection.

    The 'localhost' can be an IP Address. I tried it across the internet, thru a firewall on both ends and it works great. If you have internal and external users, you probably need to write some code to see if they are logged on to the domain or not and change the IP Address accordingly. I am still toying with that, as I have about 10 users internally and 40 users in 30 different field offices. If you have any ideas - please let me know.

    Code:
    Imports System.Data.MySqlClient
    Code:
    Dim oConnection As New MySqlConnection
            Dim oCommand As New MySqlClient.MySqlCommand
            Dim oAdapter As New MySqlDataAdapter
    
            oConnection.ConnectionString = "Host=localhost; UserName=; Password=; Database=crm;"
            oCommand.CommandText = "SELECT * FROM employees, locations where employees.location_id=locations.id"
            oCommand.Connection = oConnection
    
            oConnection.Open()
    
            Dim oReader As MySqlDataReader = oCommand.ExecuteReader(CommandBehavior.CloseConnection)
            While oReader.Read() = True
            ' !! Do something with the recordset now.
            End While

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Since it's just the connection string that's different, store the string in a config file of some sort, let it be different for the internal users, and different for the external users.

Posting Permissions

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



Click Here to Expand Forum to Full Width