Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Thursday, February 3, 2011

C# MySQL store BLOB

I needed to store a BLOB into a MySQL Database.

INSERT INTO `mytable` (`mycolumn1`, `mycolumn2`)
VALUES ('myValue1', @objectData);



_conn = new MySqlConnection();
_conn.ConnectionString = "MyConnectionString";
                   
// You must open the connection before Prepare()
_conn.Open();
 
MySqlCommand nonQueryCommand = new MySqlCommand(query, _conn);
 
nonQueryCommand.Prepare();
// Add parameter. myObjectData is my BLOB from C#
nonQueryCommand.Parameters.AddWithValue("@objectData", myObjectData);
 
nonQueryCommand.ExecuteNonQuery();
_conn.Close();

Tuesday, June 22, 2010

MySQL Workbench Foreign Key Restraint

In MySQL Workbench, the user can alter tables. When altering tables, the user can add 'foreign keys' and 'indexes' to tables.

MySQL Workbench will not allow the user to add foreign keys in certain situations, and will not give adequate error messages so the user can fix them.

Some important things to remember when altering a table to add foreign keys in MySQL Workbench.

1.
Both columns must be EXACTLY the same type. If one column is unsigned INT(10), the other must be unsigned INT(10).

2.
Since, MySQL Workbench will make an index of a foreign key, the foreign key MUST BE AN INDEX of the referenced table, otherwise the script will not be successful.

Thursday, May 21, 2009

Restore MySQL Database

When restoring a database backed-up with mysqldump ...   don't use the 'mysqldump' command to restore.  

To restore the database use 'mysql'.

'mysql -u [name] -p[password] < [filename].sql'