Ozeki NG SMS Gateway logo OZEKI NG SMS Gateway
"The World's most reliable SMS gateway software!"
info@ozekisms.com
Tel.: 00 36 52 532 731
SMS Gateway to send SMS via GSM modem or IP SMS connection Overview SMS Gateway to send SMS via GSM modem or IP SMS connection SMS Gateway to send SMS via GSM modem or IP SMS connection Quick start SMS Gateway to send SMS via GSM modem or IP SMS connection SMS Gateway to send SMS via GSM modem or IP SMS connection Download SMS Gateway to send SMS via GSM modem or IP SMS connection SMS Gateway to send SMS via GSM modem or IP SMS connection Manual SMS Gateway to send SMS via GSM modem or IP SMS connection SMS Gateway to send SMS via GSM modem or IP SMS connection How to buy SMS Gateway to send SMS via GSM modem or IP SMS connection SMS Gateway to send SMS via GSM modem or IP SMS connection FAQ SMS Gateway to send SMS via GSM modem or IP SMS connection SMS Gateway to send SMS via GSM modem or IP SMS connection Contact Us SMS Gateway to send SMS via GSM modem or IP SMS connection
OZEKI NG SMS Gateway - Product Guide

Registering remote objects Contents | SearchAJAX SMS API

Home > Product Manual > Developers Guide > C Sharp SMS API > C Sharp SMS Gateway

SMS Gateway SMS Gateway Home

  Product Manual
  Introduction
  SMS technology
  Installation Guide
  User Guide
  Developers Guide
  Tutorials
  ASP SMS API
  PHP SMS API
  HTTP SMS API
  SQL SMS API
  C Sharp SMS API
  SMS API functions
  C sharp and MS SQL Server
  Registering remote objects
  C Sharp SMS Gateway
  AJAX SMS API
  Delphi SMS API
  Cpp SMS API
  Java SMS API
  VB.NET SMS API
  Python SMS API
  Perl SMS API
  TCL/TK SMS API
  Coldfusion SMS API
  VB 6 SMS API
  Examples and Solutions
  Appendix
  FAQ
  Feature list
  Commercial Information
  Search
  Cookie policy
 


Automated phone calls?
Ozeki Phone System XE VoIP PBX software is an advanced PBX built for automated voice calls and 2 way SMS messaging. It has outstanding APIs for software developers. It can be used for:

Phone calls from SQL
Phone calls from HTTP
Voice and SMS applications

Callcenter developers
If you are working on telephone solutions, please check out the Ozeki VoIP SIP SDK.
It can be used to create VoIP client and server software.

Contact Us!
If you wish to get further information, do not hesitate to contact us!

E-mail: info@ozekisms.com

If you have a technical question, please submit a support request on-line.

How to send SMS messages from C# using an SQL database

Download: csharp-sms-example.zip C#-Mysql database example.zip

Introduction

In this article I give you an example on how you can send SMS messages to wireless devices from C#.Net. I assume, that you are familiar with Visual Studio 2003 or 2005 and the basics of databases and the SQL language. The solution described here can be used with a GSM Modem attached to your PC for sending SMS messages or it can be used with IP SMS connections.

System architecture

The system architecture used for SMS messaging consists of a GSM Modem, that is attached to the PC with a phone-to-PC datacable, an SQL-SMS Gateway software installed onto your PC, an SQL database server, such as SQL Express or MS SQL and your SMS application (Figure 1). As you can see on the figure, your SMS application will create an SQL record in the database. The SMS gateway will poll this record using an SQL SELECT statement and will send it using a GSM modem.

Figure 1. - In house SMS messaging / system architecture

Preparing your database server

To get this architecture running, first you should prepare your database. This means that you should create two database tables. One will be used for sending SMS messages (ozekimessageout) and the other will be used for receiving SMS messages (ozekimessagein). The database table you create should contain a field for sender number, recipient number and message text. For sending messages you also need a status field, that will indicate whether the message has been sent. The recommended database table layout can be seen on Figure 2. Please note that you can add extra columns to this layout freely. After creating the database table layout you should also create a username and a password that can be used to log into database.

create database ozeki
GO

use database 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)
);

GO

sp_addLogin 'ozekiuser', 'ozekipass'
GO

sp_addsrvrolemember 'ozekiuser', 'sysadmin'
GO

Figure 2. - Database table layout

Configuring the SMS Gateway

Once the database has been setup you should install and configure the SMS Gateway. The SMS Gateway we use in this article is the Ozeki NG - SMS Gateway it can be downloaded from www.ozekisms.com. There are other similar SMS gateways available. We chose this SMS Gateway, because it is very reliable, easy to configure and it is based on .NET which means it integrates well into our architecture. In the SMS gateway first you should configure the GSM modem attached to your PC. This can be done by adding a GSM Modem service provider connection. Detailed steps:

Step 1.) Open http://127.0.0.1:9501 in Internet Explorer, login with admin/abc123

Step 2.) In the "Serviceprovider connections" menu click on "Add service provider connection", then select "GSM Modem Connection" and click "Install"

Step 3.) On the GSM modem configuration form, select the com port (usually COM1) and click on autodetect to configure your modem

Step 4.) In the "Users and applications" menu click on "Add user", the select "Database user" and click on "install"

Step 5.) For username provide "sql1"

Step 6.) For connection string type select "OleDb" and for connection string enter:

Provider=SQLNCLI;Server=.\SQLEXPRESS;User ID=ozekiuser;password=ozekipass;Database=ozeki;Persist Security Info=True

Step 7.) In the configuration form I suggest you to turn on SQL logging. You can do this by enabling the checkboxes: "Log SQL SELECT statements" and "Log SQL UPDATE statements"


Figure 3. - SMS Gateway configured

After these steps you have configured the SMS Gateway to forward your messages from the database to the mobile devices.

Creating your SMS application

Once the database has been prepared and the SMS Gateway has been setup you can use Visual Studio.NET to create your SMS application. In Visual Studio create a new project of "Windows Application" type (Figure 4). This application will provide a GUI for sending the SMS message. It will connect to the database server and will insert a new record when an message is sent to a mobile phone.


Figure 4. - Application type: Windows Application

In this application you should have a form, that can be used by the user of your app to compose the message (Figure 5). This form should contain a field for the recipient number and another field for the message text. The form will have a button, that will initiate the sending process.


Figure 5. - SMS Message form

To be able to connect to your database server you should include the "using System.Data.OleDb;" directive in the using section for your code. The code for sending the SMS message is written into the event handler of the button. In this code first we connect to the database using an OleDbConnection object. For the connection we use a standard connection string. If the connection is successful (the state equals ConnectionState.Open), we execute our SQL INSERT statement to insert the SMS message. To achieve this we compose the SQL statement and we use an OleDbCommand object to execute it (Figure 6).

     private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //Connect to the database
                OleDbConnection conn = new OleDbConnection();

                conn.ConnectionString = "Provider=SQLNCLI;Server=.\\;"+
                "User ID=ozekiuser;password=ozekipass;Database=ozeki;Persist
                Security Info=True";
                conn.Open();
                if (conn.State == ConnectionState.Open)
                {
                    //Send the message
                    OleDbCommand cmd = new OleDbCommand();
                    cmd.Connection = conn;
                    string SQLInsert =
                        "INSERT INTO "+
                        "ozekimessageout (receiver,msg,status) "+
                        "VALUES "+
                        "('"+tbSender.Text+"','"+tbMsg.Text+"','send')";
                    cmd.CommandText = SQLInsert;
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Message sent");
                }

                //Disconnect from the database
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

Figure 6. - Sending an SMS message source code

Verifying your SMS application

After executing the application, you can send your first SMS message. To track the message you can use an SQL console to see what is inserted into your SQL table and you should examine the event log of the SMS gateway to see the SQL events. The eventlog of the Ozeki NG SMS gateway is located at the following location:

C:\Program Files\Ozeki\OzekiNG - SMS Gateway\Logs

References

1.) You can download SQLExpress free of charge from the following URL:
http://msdn2.microsoft.com/en-us/express/aa718378.aspx  

2.) Ozeki NG - SMS Gateway can be downloaded from the following URL:
http://www.ozekisms.com/

3.) Additional information for setting up SQL Express is available at:
http://www.ozekisms.com/sms-gateway/index.php?owpn=305

Good luck!

Dig deeper!
People who read this also read...


C Sharp SMS API C Sharp and MS SQL Server Ozeki NG Installation Guide
FAQ



Next page: AJAX SMS API
Copyright © 2000 - 2017 Ozeki Informatics Ltd.
All rights reserved

Software PBX for Windows | VoIP SDK   |   Legal information   |   Privacy policy   |   Terms of use
Please, address your inquiries to info@ozekisms.com