Archive for April, 2007

Parameterized Queries With ASP.net and MySQL

Most of the documentation and samples of using parameterized queries assumes that you are using MS SQL server as your backend. In that setup you can use this sort of SQL code in the asp:SqlDataSource tag:

SelectCommand="SELECT tracking, date, author, contents, private FROM glpi_followups WHERE tracking = @tracking"

Trying to use this same code for MySQL will return nothing. To get it to work with MySQL you need to use a ? instead of the @parameter.

SelectCommand="SELECT tracking, date, author, contents, private FROM glpi_followups WHERE tracking = ?"

What I have not figured out is if you have more than one parameter how do you use make one ? seem different than the next ?. If anyone has the solution to that one, please let me know.

Comments

MySQL Replication

We have a RAIC (Redundant Array of Inexpensive Computers) that control our entire conveyor system through out the manufacturing plant. This conveyor system is responsible for staging product and placing it behind machine when a particular order has been scheduled to sending final product all the way down to the truck docks. If this system were to go offline it makes getting product through a much more labor intensive process. So we have this system that keeps track of all order, where they are on the conveyors, when they are scheduled etc. The base of this system runs off of MySQL on Linux servers. If we loose this database everything is lost and we would have to hand enter every product and where it is staged on the line. Not something we want to do.

So I did a little reading and setup MySQL replication with a Master-Slave relationship. Really quite an easy process and extremely quick in getting the data out to the slave. Below are the steps I used to complete this task. This was done on RedHat Enterprise 4.4 and MySQL 4.1.20.

Setup The Master
On the master server edit the /etc/my.cnf file. In the [mysqld] section add the following lines:

# database replication
log-bin
binlog-do-db=database-name
server-id=1

Restart MySQL.
/etc/init.d/mysql restart

Log into the MySQL server /etc/init.d/mysql restart and enter the following query:
GRANT REPLICATION SLAVE ON *.* TO ‘replication-user-account‘@’%’ IDENTIFIED BY ‘password‘;
FLUSH PRIVILEGES;

USE database-name;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

Make a note of the file and position from the query results you will need this later.

QUIT;

Make a dump of the database to copy to the slave machine.
mysqldump -u root -p –opt database-name > /tmp/database-name.sql

Once you have the dump log back into the MySQL server and issue the following commands;
UNLOCK TABLES;
QUIT;

Copy the database dump to the slave machine:
scp /tmp/database-name.sql root@slave.domain.com:/tmp

Setup The Slave
Log into the slave server.

Log into the MySQL server:
mysql -u root -p

Create a new database:
CREATE DATABASE database-name;
QUIT;

Copy sql dump into the database:
mysql -u root -p database-name < /tmp/database-name.sql

On the slave server edit the /etc/my.cnf file. In the [mysqld] section add the following lines:

# database replication
server-id=2
master-host=master.domain.com
master-user=replication-user-account
master-password=password
master-connect-retry=60
replicate-do-db=database-name

Restart the MySQL service.
/etc/init.d/mysqld restart

Log into the MySQL server and issue the following commands:
SLAVE STOP;
CHANGE MASTER TO MASTER_HOST=‘master.domain.com’, MASTER_USER=‘replication-user-account’, MASTER_PASSWORD=‘password’, MASTER_LOG_FILE=’server-bin.000001′, MASTER_LOG_POS=101091;
Be sure to replace MASTER_LOG_FILE and MASTER_LOG_POS with the values you noted when setting up the master server
SLAVE START;
QUIT;

Comments

Hold Music

We have classical music for our music on hold and we have the Customer Service department telling us that customers are complaining about our “horrible hold music”. Apparently our customers have a lack of culture issue they need to address. So in an attempt to silence the complaint we are trying to find some royalty free music to use for the hold songs. About the only thing we can find is the new age stuff or acid jazz that sounds like a porn movie soundtrack. We are leaning towards the porn music because if we can get them horny for our product!

Comments (2)