Connect to Microsoft SQL Server with MBS Xojo SQL Plugin
1. With loading driver directly:
Some example code using SQLDatabaseMBS, but may look very similar with SQLConnectionMBS class:
As you see, we point to the dylib as ODBC library, load it and connect through it.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
2. With loading iODBC and having driver in connection string
As you see, we let the plugin load libiodbc.dylib (ODBC manager) and then have it load the library.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
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.