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:

MainForm.cs:
Shows and handles a "Compose message" button and 2 ListView items for incoming and outgoing messages.

ComposeMessageForm.cs:
Shows and handles the necessary data fields for creating a new message.

DatabaseHandling.cs:
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.

Code:
public MainForm()
{
InitializeComponent();

listViewOut.View = View.Details;
listViewOut.ShowItemToolTips = true;
listViewOut.Columns.Add("ID", 50);
listViewOut.Columns.Add("Sender", 100);
listViewOut.Columns.Add("Receiver", 100);
listViewOut.Columns.Add("Sent time", 100);
listViewOut.Columns.Add("Received time", 100);
listViewOut.Columns.Add("Operator", 50);
listViewOut.Columns.Add("Status", 50);
listViewOut.Columns.Add("Message type", 50);
listViewOut.Columns.Add("Message text", 100);

listViewIn.View = View.Details;
listViewIn.ShowItemToolTips = true;
listViewIn.Columns.Add("ID", 50);
listViewIn.Columns.Add("Sender", 100);
listViewIn.Columns.Add("Receiver", 100);
listViewIn.Columns.Add("Sent time", 100);
listViewIn.Columns.Add("Received time", 100);
listViewIn.Columns.Add("Operator", 50);
listViewIn.Columns.Add("Message type", 50);
listViewIn.Columns.Add("Message text", 100);
}

private void buttonComposeMessage_Click(object sender, EventArgs e)
{
ComposeMessageForm cmf = new ComposeMessageForm();
cmf.ShowDialog(this);
updateOutgoingMessages();
updateIncomingMessages();
}
...
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.

Code:
ComposeMessageForm.cs
...
private void buttonSend_Click(object sender, EventArgs e)
{
CheckAndSendMessage();
}

private void CheckAndSendMessage()
{
if (textBoxRecipient.Text == "")
{
MessageBox.Show("Recipient field mustn't be empty!",
"Incorrect field value");
return;
}

string errorMsg = "";
DatabaseHandling.insertMessage(textBoxRecipient.Text,
textBoxMessageText.Text, out errorMsg);

MessageBox.Show(errorMsg, "Result of inserting message");
}
...
******************************

Code:
DatabaseHandling.cs
...
public static void insertMessage(string receiver, string messageText,
out string errorMsg)
{
Connect(out errorMsg);
if (errorMsg != "")
return;

try
{
SqlCommand sqlComm = sqlConn.CreateCommand();
sqlComm.CommandText = "insert into ozekimessageout " +
"(msgtype,receiver,msg,status) " +
"values ('SMS:TEXT','" + receiver + "','" +
messageText + "','send');";
if (sqlComm.ExecuteNonQuery() == 0)
{
errorMsg = "Insert was UNsuccessful!";
}
else
{
errorMsg = "Insert was successful!";
}
}
catch (Exception e)
{
errorMsg = e.Message;
}

CloseConnection();
}
...
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.

Code:
DatabaseHandling.cs
...
public static void updateListViewOut(ListView lvOut)
{
string errorMsg = "";
Connect(out errorMsg);
if (errorMsg != "")
return;

lvOut.Items.Clear();

try
{
SqlCommand sqlComm = sqlConn.CreateCommand();
sqlComm.CommandText = "select id,sender,receiver,msg,senttime," +
"receivedtime,operator,msgtype,status from ozekimessageout;";

SqlDataReader dr = sqlComm.ExecuteReader();
if (dr != null)
{
while (dr.Read())
{
string tmpStr = "";
tmpStr = (dr.IsDBNull(0)) ? ("") : (dr.GetInt32(0).ToString()); //id
ListViewItem lvi = new ListViewItem(tmpStr);
tmpStr = (dr.IsDBNull(1)) ? ("") : (dr.GetString(1)); //sender
lvi.SubItems.Add(tmpStr);
tmpStr = (dr.IsDBNull(2)) ? ("") : (dr.GetString(2)); //receiver
lvi.SubItems.Add(tmpStr);
tmpStr = (dr.IsDBNull(4)) ? ("") : (dr.GetString(4)); //senttime
lvi.SubItems.Add(tmpStr);
tmpStr = (dr.IsDBNull(5)) ? ("") : (dr.GetString(5)); //received time
lvi.SubItems.Add(tmpStr);
tmpStr = (dr.IsDBNull(6)) ? ("") : (dr.GetString(6)); //operator
lvi.SubItems.Add(tmpStr);
tmpStr = (dr.IsDBNull(8)) ? ("") : (dr.GetString(8)); //status
lvi.SubItems.Add(tmpStr);
tmpStr = (dr.IsDBNull(7)) ? ("") : (dr.GetString(7)); //msgtype
lvi.SubItems.Add(tmpStr);
tmpStr = (dr.IsDBNull(3)) ? ("") : (dr.GetString(3)); //msg
lvi.SubItems.Add(tmpStr);
lvOut.Items.Add(lvi);
}
dr.Close();
}

sqlConn.Close(); //we close the SQL connection
}
catch (Exception)
{

}

CloseConnection();
}
If you wish to create an SMS sending application to send SMS from MSSQL, you can get some tips from this site: ozekisms.com/index.php?owpn=286

Sayfuddin