« Plugin wishes for mac… | Home | MBS Xojo Plugins, ver… »

Crossplatform connection to Microsoft SQL Server in Xojo

Today we got updated sample code to connect from Mac, Windows and Linux to Microsoft SQL Server. As you see we use freetds on MacOS and Linux to connect to the SQL Server and ODBC or DB Library on Windows. Please try soon with SQLDatabaseMBS or SQLConnectionMBS classes with MBS Xojo SQL Plugin:

// connect to Microsoft SQL Database Dim con As New SQLDatabaseMBS dim cs as string dim user as string = iUser.Text dim pass as string = iPass.Text dim databaseName as string = iDatabaseName.text dim server as string = iServer.text dim Port as string = iPort.Text #if TargetLinux then // install package tdsodbc cs = "DRIVER={libtdsodbc.so};Server="+Server+";UId="+User+";PWD="+Pass+";Database="+DatabaseName+";TDS_VERSION=7.2;Port="+Port con.DatabaseName = "ODBC:"+cs con.Option("UseAPI") = "ODBC" #elseif TargetWin32 then cs = Server + "@"+DatabaseName con.UserName = User con.Password = Pass con.Option("OLEDBProvider") = "SQLNCLI" con.DatabaseName = "SQLServer:"+cs #elseif TargetMacOS then dim libtdsodbc as Folderitem = FindFile("libtdsodbc.dylib") // download library on MBS website: // http://monkeybreadsoftware.de/xojo/download/plugin/Libs/ cs = "DRIVER={" + libtdsodbc.nativepath + "};Server="+Server+";UId="+User+";PWD="+Pass+";Database="+DatabaseName+";TDS_VERSION=7.2;Port="+Port con.Option("UseAPI") = "ODBC" con.DatabaseName = "ODBC:"+cs #else ? #endif // DB Library settings con.Option("DBPROP_INIT_TIMEOUT") = "10" con.Option("DBPROP_COMMANDTIMEOUT") = "10" // ODBC settings con.Option("SQL_ATTR_QUERY_TIMEOUT") = "10" con.Option("SQL_ATTR_CONNECTION_TIMEOUT") = "10" if con.ConnectMT then con.Scrollable = True // if you like to get exceptions instead of checking error property con.RaiseExceptions = true Else dim e as string = con.errorMessage System.DebugLog e Break end if
PS: Due to a required change in SQL Plugin, you need 18.3pr2 version, which comes in the next days. The biggest plugin in space...
15 06 18 - 19:23