« Read HEIC or HEIF ima… | Home | Windows DLL Loading e… »

Connect to Oracle via MBS Xojo SQL Plugin

We recently had a client asking how to connect to Oracle database with MBS Xojo SQL Plugin. So first install Instant Client. For that download it, unzip the folder and put it somewhere you like to have it, e.g. in a C:\Oracle folder. Next you need to add the folder to the PATH variable, so you go to My Computer -> Properties -> Advanced -> Environment Variables -> PATH and add in the list as first item the path to the folder with the instant client libraries, e.g. C:\Oracle\instantclient_19_3.

Now you can use SQLDatabaseMBS or SQLConnectionMBS classes to connect. You may need to specify the database connection string. As we use Oracle, it starts with "Oracle:", so SQLDatabaseMBS knows which driver to use. Next you specify hostname with optional port and service name in format <hostname>[:<port>][/<service_name>]. Please also set option with kOptionLibraryOracle constant to the path pointing to the DLL file. You can either use SetFileOption with folder item, Option() with file path or just let it away and the plugin will look for oci.dll itself. Here some example code:

Dim db As New SQLDatabaseMBS // where is the oci.dll library? Dim fa As FolderItem = GetFolderItem("C:\Oracle\instantclient_19_3\oci.dll", FolderItem.PathTypeNative) DB.SetFileOption(SQLConnectionMBS.kOptionLibraryOracle, fa) DB.DatabaseName = "Oracle:" + "localhost:1521/XE" DB.UserName = "zEPI" DB.Password = "root" if DB.Connect then MsgBox "We are connected. Server Version: " + db.ServerVersionString else MsgBox db.ErrorMessage end if
Please do not hesitate to contact us with your questions.
20 08 19 - 09:57