« StyledText for Excel … | Home | 20th Birthday Cake »

Connect to Microsoft SQL Server with MBS Xojo SQL Plugin


We have made a ton of example code in the last decade showing how to connect to Microsoft SQL Server from MacOS or Linux using FreeTDS and our MBS Xojo SQL Plugin. And there are two ways to do it:

1. With loading driver directly:

Some example code using SQLDatabaseMBS, but may look very similar with SQLConnectionMBS class:

Dim libtdsodbc as Folderitem = FindFile("libtdsodbc.dylib")
Dim cs as string = "DRIVER={FREETDS};Server="+Server+";UId="+User+";PWD="+Pass+";Database="+DatabaseName+";TDS_VERSION=7.2;Port="+Port
db.SetFileOption db.kOptionLibraryODBC, libtdsodbc
db.Option("UseAPI") = "ODBC"
db.DatabaseName = "ODBC:"+cs

As you see, we point to the dylib as ODBC library, load it and connect through it.

2. With loading iODBC and having driver in connection string

Dim libtdsodbc as Folderitem = FindFile("libtdsodbc.dylib")
Dim cs as string = "DRIVER={" + libtdsodbc.nativePath + "};Server="+Server+";UId="+User+";PWD="+Pass+";Database="+DatabaseName+";TDS_VERSION=7.2;Port="+Port
db.Option("UseAPI") = "ODBC"
db.DatabaseName = "ODBC:"+cs

As you see, we let the plugin load libiodbc.dylib (ODBC manager) and then have it load the library.

What is better?

Both ways do work, so for most customers there is no difference. But the second way is better as the libiodbc does some additional services like text encoding conversations, provide additional functions like a directory of the various database drivers, functions to browser for databases and a way to work with data sources.

So we recommend in general that all customers prefer the second way over the ODBC manager to make sure all things work well. For the next weeks, we'll try to update a couple of blog posts and examples projects. The biggest plugin in space...
23 04 20 - 20:49