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 following page. If it is done, please check if VB.NET can read and write database records.
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:
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:
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
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).
Step 4 - Insert SMS record into database
The following code inserts textbox content from the VB.NET example GUI to the database (Code 4).
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.
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.
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.
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.