I tried to create an application to send SMS using C#.NET through MS SQL Server. I have found some codes and examples in Ozeki NG SMS Gateway documentation.
The downloadable code inserts the message to be sent into the ozekimessageout database table. Ozeki NG SMS Gateway periodically checks the table, and if it finds a row where the status is send, it will try to send it. In the script you have to set the server name to where the MS SQL Server is running, the username (specifying who can log in to the MS SQL Server) with the password and the type of the SMS message.
The source code of the example application is structured in the following way:
Shows and handles a "Compose message" button and 2 ListView items for incoming and outgoing messages.
Shows and handles the necessary data fields for creating a new message.
Handles the database and refreshes the 2 ListView items.
Description of the process:
Step 1: Creating the form
Through MainForm.cs in the ComposeMessageForm.cs file, you create the form that requests the sms data. The User fills in the necessaries. The user will be asked to fill in the Recipient and Message text fields. A pop-up messagebox is used to inform the User about error(s) or result(s) of sending the message.
In MainForm.cs file you set the 2 ListView items (view mode and names of columns). In the buttonComposeMessage_Click(...) procedure the ComposeMessageForm is called to compose a new message. After closing that box the 2 ListView items will be refreshed.
Step 2: Processing data coming from the form
After filling in the fields and clicking the Send button, the application receives the information about the form. In the ComposeMessageForm.cs file, the CheckAndSendMessage() procedure is called by "buttonSend_Click(...)". At the beginning of the procedure, check the data of the textbox fields. The Recipient box is mandatory. If it is empty, the processing will be aborted, and the User will be informed about the error. If the checking is successful, you will insert a new row into the ozekimessageout database table (in DatabaseHandling.insertMessage(...)).
We need the following: the address of the computer running the Microsoft SQL Server [the default address is (local)\SQLExpress ((local) means that MS SQL Server is installed on the same computer on which the C#.NET application is running)], the username (who is authorized to log in to the MS SQL Server and to insert messages, the user's password, the message type (the default is SMS:TEXT), the recipient and the message data.
private void buttonSend_Click(object sender, EventArgs e)
private void CheckAndSendMessage()
if (textBoxRecipient.Text == "")
MessageBox.Show("Recipient field mustn't be empty!",
"Incorrect field value");
string errorMsg = "";
textBoxMessageText.Text, out errorMsg);
MessageBox.Show(errorMsg, "Result of inserting message");
Step 3: Checking the incoming and the outgoing message table
By refreshing the table of incoming and outgoing messages, you can check the incoming messages and the status of outgoing messages. Look at the updateListViewOut() procedure. First, you clear its rows. Then, you create the connection. If it is successful, you will refill the outgoing messages table.