Microsoft SQL Server
Microsoft SQL Server (MSSQL) is a powerful database server that is commonly used in large companies that rely on Microsoft tools. To use it, you need to copy/move the MSSQLServerPlugin file from the Extras > Database Plugin Resources folder to the Plugins folder (it is there by default). The plugin supports connecting to Microsoft SQL Server from Windows only.
You can connect to Microsoft SQL Server from Desktop, Web and Console projects.
Note
Connecting from a mobile app is not supported as holding a connection open is generally not supported by iOS itself due to the constant energy usage that would produce.
For more information about Microsoft SQL Server, refer to their web site: www.microsoft.com/sqlserver
Connecting to Microsoft SQL Server
To connect to Microsoft SQL Server (MSSQL), you need to have a MSSQL server installed on either your computer or an accessible server. You 'll need to know several things about this installation, including:
The Host IP address or name
The name of the database on the server
The username to use to connect to the server
The password to use to connect to the server
With this information, you can connect to the database on the server using the MSSQLServerDatabase class:
Var db As New MSSQLServerDatabase
db.Host = "192.168.1.172"
db.DatabaseName = "BaseballLeague"
db.UserName = "broberts"
db.Password = "streborb"
Try
db.Connect
// Use the database
Catch error As DatabaseException
MessageBox(error.Message)
End Try
Creating a table
This SQL creates the Team table used in previous examples:
CREATE TABLE Team (ID INT NOT NULL IDENTITY PRIMARY KEY, Name TEXT, Coach TEXT, City TEXT);
In place of the TEXT data type, which allows an unlimited length string, you might also use the VARCHAR data type which allows you to specify a maximum size for the string:
CREATE TABLE Team (ID INT NOT NULL IDENTITY PRIMARY KEY, Name VARCHAR(100), Coach VARCHAR(100), City VARCHAR(100));
Auto-incrementing primary keys
If a table has the IDENTITY attribute assigned to a primary key, then that column auto-increments when a row is added to the table. When you INSERT data into a table with a primary key, you omit the primary key from the INSERT SQL:
INSERT INTO Team (Name)
VALUES ('Seagulls');
After adding a row to the database, you can get the value of the last primary key value by accessing the special column @@IDENTITY in a SELECT statement:
db.ExecuteSQL("SELECT @@IDENTITY;")
See also
MSSQLServerDatabase class; Database Basics for beginners, Adding, updating and deleting rows topics