Saturday, November 25, 2006

Auto Increment Primary Key in MS SQL Server

MySQL database has a great functionality and one of them is auto_increment. How to make a field as an auto_increment field in SQL Server 2000 ?

The key is, set the table field to be an identity column.

You can do this in Enterprise Manager in the Design Table mode or through SQL Query Analyzer. The code below is the SQL sample to create an auto_increment field :

CREATE TABLE trel_user_menu
(
usermenu_id int IDENTITY(1,1)PRIMARY KEY CLUSTERED,
menu_id smallint NOT NULL,
user_nick varchar(16) NOT NULL,
usermenu_status tinyint NOT NULL
)

The 1's following the IDENTITY keyword indicate the SEED number (value for first record in table) and increment property (0 or 1).

Hope this helps.

Friday, November 03, 2006

Possible Reasons for +CMS ERROR: 302

It's possible if we are working with AT Command we could get the +CMS ERROR: 302. But what circumstances do I get +CMS ERROR: 302?

CMS ERROR 302 means "Operation not allowed".
Possible reasons for this error are :
(1) The service may be unavailable during that time.
(2) Service provider has locked the service.
(3) Corporate lock is active
(4) Module was powered off by +CPOF, CFUN=0, unplug, or Low battery level
(5) Service not correctly loaded
(6) SIM does not support SMSCB

Hope this helps.

Wednesday, November 01, 2006

Bash Script to Handling gnokii Daemon

Dear, if we are working with gnokii, sometimes after a few minutes gnokii got hang-up or the sms can not stored (save to the database) or can not send (get from the database and sent it out). So, we must stop the gnokii processed daemon and then start it again. But, i think it's a waste time if we are always stop and start it again. And the worst thing is we didn't know when the gnokii got hang-up. Below is my own bash script to handle this situation.


#!/bin/bash
#
# (c) Asep Andria I.W., ST.
# Email : <asep.andria@gmail.com>
# Mobile : +6285659969486

# ----------------------------------
# Check mysql.sock
# ----------------------------------

MYSQL_SOCK_DIR="/opt/lampp/var/mysql";
MYSQL_SOCK_NAME="mysql.sock";

if [ ! -x "$MYSQL_SOCK_DIR/$MYSQL_SOCK_NAME" ]; then

echo "Can not found $MYSQL_SOCK_NAME in $MYSQL_SOCK_DIR"
echo "Please check if MySQL Server is running or change the location of $MYSQL_SOCK_NAME"
echo "Exiting..."

exit 1

fi

# ----------------------------------
# Linking mysql.sock
# ----------------------------------

MYSQL_SOCK_LINK_DIR="/var/run/mysqld";
MYSQL_SOCK_LINK_NAME="mysqld.sock";

if [ ! -x "$MYSQL_SOCK_LINK_DIR/$MYSQL_SOCK_LINK_NAME" ]; then

echo "Can not found $MYSQL_SOCK_LINK_NAME in $MYSQL_SOCK_LINK_DIR"
echo ""
echo "Trying to linking $MYSQL_SOCK_DIR/$MYSQL_SOCK_NAME to $MYSQL_SOCK_LINK_DIR/$MYSQL_SOCK_LINK_NAME ..."

/bin/ln -s "$MYSQL_SOCK_DIR/$MYSQL_SOCK_NAME" "$MYSQL_SOCK_LINK_DIR/$MYSQL_SOCK_LINK_NAME"

if [ ! -x "$MYSQL_SOCK_LINK_DIR/$MYSQL_SOCK_LINK_NAME" ]; then

echo "Failed to linking $MYSQL_SOCK_DIR/$MYSQL_SOCK_NAME to $MYSQL_SOCK_LINK_DIR/$MYSQL_SOCK_LINK_NAME"

exit 1

else

echo "Success to linking $MYSQL_SOCK_DIR/$MYSQL_SOCK_NAME to $MYSQL_SOCK_LINK_DIR/$MYSQL_SOCK_LINK_NAME"

fi

fi

# ----------------------------------
# gnokii smsd path
# ----------------------------------
SMSD_PATH="/usr/local"

while true
do
killall smsd >/dev/null 2>&1
sleep 3
$SMSD_PATH/sbin/smsd -u usersms -d sms -c localhost -m mysql >/dev/null 2>&1 &
sleep 1m
done


Sometimes the mysql.sock location is differ from the os/machine to other. So, in the script above i tried to find the mysql.sock location. If exist ignore it but if not exist create a link one. We need this mysql.sock because gnokii didn't work if gnokii didn't find the mysql socket. Of course this script useful when you want to combine gnokii with MySql database.

Hope this script giving you a new inspiration.