Search code examples
mysqldatabase-connectionlotusscriptlotus

LotusScript - How to connect to MySQL?


Sorry for possible dublicate.

I am trying to connect to my MySQL database from my LotusScript code (in some of my legacy projects):

Option Public
Option Declare

UseLSX "*LSXODBC"

Sub Initialize
    Dim mysqlConnection As New ODBCConnection
    Dim sqlQuery As New ODBCQuery
    Dim result As New ODBCResultSet

    Call mysqlConnection.ConnectTo("url","root","111111")
    If Not mysqlConnection.IsConnected Then
        MessageBox "No connection. Try again later."
        Exit Sub
    Else 
        MessageBox "Connection success."
    End If
End Sub

I can't figure out what is the correct way to set the url of my database in LotusScript. I have already tried many variants of possible solutions, but nothing worked, also found many different urls, but also not helped.

Situation:

For example, I am trying to connect to my localhost MySQL base in port 3306 with name "test_db".

Question:

How must the url looks like for this?

p.s. also, if you have more possible ways to connect to MySQL DB from LotusScript - I will be very glad to see them.

Thanks.


Solution

  • As per the documentation for the ConnectTo method of ODBCConnetion class, you don't specify a URL. You specify a Data Source Name, otherwise known as a DSN. This is a name that you assign when you configure a connection in the 'Data Sources (ODBC)' tool on the Windows machine where the code will be executing.

    On Windows 10, the 'Data Sources (ODBC)' tool is found in the Control Panel listed under Administrative Tools. On a Windows 2008 server that I happen to have handy, Administrative Tools is directly on the Start Menu. I'm sure they've hidden it in other places on other Windows versions. (I have a dim memory of it being under 'Accessories' on some versions.)

    Note that on 64 bit versions of Windows, you need to be cognizant of whether your code is running in a 32 bit environment - as it is if it runs in the Notes client, or in a 64 bit environment, which it might be if it is running in background on a Domino server. There are separate 32 and 64 bit versions of the 'Data Sources (ODBC)' tool, and it does matter which one you use. If you're at all unsure, run them both and configure the same DSN name in each of them,