- Quick Start Guide
- System requirements
- Installation guide
- Mobile networks
- User guide
- Developers guide
- SMS from SQL
- HTTP API
- PHP SMS API
- C# SMS API
- VB.NET SMS API
- VB.NET sms script
- VB.NET database SMS example
- Send SMS From VB.NET using database
- VB.NET HTTP SMS example
- Service providers
VB.NET database SMS example
See how to add SMS functionality to your VB.NET application. For the solution you will need a database server that stores sent and received messages. MS SQL, MS SQL Express, MySQL, Access, Oracle is accepted. The source code is provided. You can download and edit it.
Download: vb.net-sms-example-sql.zip (70 Kb)
The solution consists of 3 different parts (Figure 1). Ozeki SMS Gateway, the SQL database and your VB.NET application.
Check if Ozeki SMS Gateway is connected to the SQL database. You can find plenty of connection tutorials on the
Figure 1 - Send and receive SMS messages with VB.NET
The figure shows exactly what was described in the last paragraph. You can send SMS messages by inserting a new record by using the VB.NET application. Check the SQL table to see if new records were placed into it. These messages should be automatically sent. Check if the VB.net application works with the database both by reading or inserting records. Reading records are important since this is the way to read incoming messages.
The main software of the operation is Ozeki SMS Gateway which you can get to your Ozeki 10 application. This software can connect your computer to the mobile network as it can connect your PC to any of the following database server:
- send SMS from Microsoft SQL Express
- send SMS from Access
- send SMS from MySQL
- send SMS from Oracle
- send SMS from Postgres
- send SMS from SAP SQL Anywhere
You will also need a C# or Visual Basic development IDE, such as Microsoft Visual Studio. If you haven't done yet, please download example project. To sum it up, here is a full list of the required software:
- Ozeki SMS Gateway
- Database server (MS SQL, SQL Expres, Access, MySQL, Oracle, Postgres, SAP SQL Anywhere, etc)
- Microsot Visual Studio
How to Install and Configure VB.NET
Use the following steps to create a working solution. In this example you will see a Microsoft SQL Express solution with database examples ready to copy-paste. Please download and install Ozeki 10 before going forward with these steps. Manually test if you can send and receive SMS message with Ozeki 10. If the test was successful, you will be able to send and receive SMS messages from the graphical user interface of the VB.net application. Check if it was sent by using the event logs of Ozeki 10.
If you are not using SQL Express, please copy the table creation code from one of these SQL server options.
Step 1 - Create database user and tables
create database ozeki GO
use ozeki GO
CREATE TABLE ozekimessagein ( id int IDENTITY (1,1), sender varchar(30), receiver varchar(30), msg varchar(160), senttime varchar(100), receivedtime varchar(100), operator varchar(30), msgtype varchar(30), reference varchar(30), );
CREATE TABLE ozekimessageout ( id int IDENTITY (1,1), sender varchar(30), receiver varchar(30), msg varchar(160), senttime varchar(100), receivedtime varchar(100), operator varchar(100), msgtype varchar(30), reference varchar(30), status varchar(30), errormsg varchar(250) );
sp_addLogin 'ozekiuser', 'ozekipass' GO
sp_addsrvrolemember 'ozekiuser', 'sysadmin' GO
Step 2 - Connect Ozeki SMS Gateway to your database
Now it is time to create a Database user in Ozeki 10. After the user has been created select 'SQL server' and copy-paste the following connection string (Code 2). Do not forget to use your own Database name, user ID and password.
Step 3 - Modify the VB.NET code to connect with Ozeki 10
Open example project in Visual Studio and edit source code if necessary. In code 3 you should provide the same connection parameters used above in code 2. The VB.NET parameters are added to 'myConnection' connection string (Code 3).
Dim dbUsername As String = "ozekiuser" Dim dbPassword As String = "ozekipass" Dim database As String = "ozeki" Dim myConnection As New SqlConnection("Server=.\SQLEXPRESS;User ID=" _ & dbUsername _ & ";password=" _ & dbPassword _ & ";Database=" _ & database _ & ";Persist Security Info=True")
Step 4 - Insert SMS record into database
The following code inserts textbox content from the VB.NET example GUI to the database (Code 4).
Dim mySqlQuery As String = "INSERT INTO ozekimessageout (receiver,msg,status) " _ & "VALUES ('" & tbReceiver.Text & "', '" & tbMessage.Text & "', 'send');" Dim mySqlCommand As New SqlCommand(mySqlQuery, myConnection)
This code can only execute if the VB.NET application can connect to the database. The insertable values can be provided in the application GUI (Figure 2). After typing the recipient's number and message text, click 'Insert' and Ozeki 10's Database User will forward the inserted message to the recipient after finding the record in the database.
Figure 2 - The user GUI of this VB.NET example
Finally the code sequence on the bottom of the class will run (Code 5). These 3 methods will be called. They will connect to the database and insert the message record of the SMS to send and close the connection.
myConnection.Open() mySqlCommand.ExecuteNonQuery() myConnection.Close()
Full VB.NET example code
The full code you can see below (Code 6) is built up from segments described above (Code 3 - 5). You can freely use and modify the example code as you wish. The method can drop an exception if it cannot INSERT the SMS message to send.
Imports System Imports System.Data Imports System.Data.SqlClient Public Class Form1 Private Sub bSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bSend.Click Try Dim dbUsername As String = "ozekiuser" Dim dbPassword As String = "ozekipass" Dim database As String = "ozeki" Dim myConnection As New SqlConnection("Server=.\SQLEXPRESS;User ID=" _ & dbUsername _ & ";password=" _ & dbPassword _ & ";Database=" _ & database _ & ";Persist Security Info=True") Dim mySqlQuery As String = "INSERT INTO ozekimessageout (receiver,msg,status) " _ & "VALUES ('" & tbReceiver.Text & "', '" & tbMessage.Text & "', 'send');" Dim mySqlCommand As New SqlCommand(mySqlQuery, myConnection) myConnection.Open() mySqlCommand.ExecuteNonQuery() myConnection.Close() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub End Class
With this solution you won't have to worry about queing outgoing messages, since the queue will be handled by Ozeki 10's SMS Gateway application. It will also ad a timestamp and modify the message status register attribute to show successful or unsuccessful delivery towards the recipient.
They will be received and stored on the database server as well. Although the VB.NET application doesn't need to be online when receiving a message, since it can view the 'ozekimessagein' table anytime it goes online by running a SELECT statement over the table.