Platforms to show: All Mac Windows Linux Cross-Platform
/SQL/SQLDatabaseMBS Microsoft SQL via ODBC on Linux
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /SQL/SQLDatabaseMBS Microsoft SQL via ODBC on Linux
This example is the version from Fri, 23th Apr 2020.
Project "SQLDatabaseMBS Microsoft SQL via ODBC on Linux.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
// install package tdsodbc
// connect
dim con as new SQLDatabaseMBS
try
// we used Microsoft SQL Server 2008 and run app on Linux to test this
Dim cs As String = "DRIVER={libtdsodbc.so};Server="+iServer.Text+";UId="+iUser.Text+";PWD="+iPass.Text+";Database="+iDatabaseName.Text+";TDS_VERSION=7.2;Port="+iPort.Text
// alternative way is with full path to libtdsodbc.so in connection string
con.Option("UseAPI") = "ODBC"
con.DatabaseName = "ODBC:"+cs
if con.Connect then
con.Scrollable = false // disabling scrolling cursors is much faster for Microsoft SQL Server...
con.RaiseExceptions = true // if you like to get exceptions instead of checking error property
// add time stamp
'con.SQLExecute "insert into "+iTable.text+" ("+iColumn.text+") VALUES (SYSUTCDATETIME())"
// no commit as we have autocommit
MsgBox "Connected."
'dim sql as string = "select * from test"
'dim r as RecordSet = con.SQLSelect(sql)
'if con.Error then
'MsgBox con.ErrorMessage
'else
'MsgBox r.IdxField(1).name+": "+r.IdxField(1).StringValue
'end if
// Disconnect is optional
// autodisconnect will ocur in destructor if needed
con.close
else
MsgBox "not connected: "+con.errorMessage
end if
catch r as RuntimeException
MsgBox r.message
end try
End EventHandler
EventHandler Sub Open()
if TargetLinux then
me.Height = 24
end if
End EventHandler
End Control
Control iServer Inherits TextField
ControlInstance iServer Inherits TextField
End Control
Control iPort Inherits TextField
ControlInstance iPort Inherits TextField
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control iUser Inherits TextField
ControlInstance iUser Inherits TextField
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control iPass Inherits TextField
ControlInstance iPass Inherits TextField
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control iDatabaseName Inherits TextField
ControlInstance iDatabaseName Inherits TextField
End Control
Function FindFile(name as string) As FolderItem
// Look for file in parent folders from executable on
dim parent as FolderItem = app.ExecutableFile.Parent
while parent<>Nil
dim file as FolderItem = parent.Child(name)
if file<>Nil and file.Exists then
Return file
end if
parent = parent.Parent
wend
End Function
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project
See also:
- /SQL/SQLDatabaseMBS CubeSQL prepared statement
- /SQL/SQLDatabaseMBS CubeSQL select version
- /SQL/SQLDatabaseMBS Microsoft SQL Server Data Types
- /SQL/SQLDatabaseMBS MSSQL Execute
- /SQL/SQLDatabaseMBS MySQL Connect
- /SQL/SQLDatabaseMBS Oracle Connect
- /SQL/SQLDatabaseMBS SQLite Blob test
- /SQL/SQLDatabaseMBS SQLite Encryption Fetch values
- /SQL/SQLDatabaseMBS SQLite insert record
- /SQL/SQLDatabaseMBS SQLite insert record with transaction
The items on this page are in the following plugins: MBS SQL Plugin.