Thursday, 6 August 2009

MySQL server has gone away Error on restore from backup

when you are restoring from a backup of a large db you get this strange error from mysql: "MySQL server has gone away Error"

to cure it open mysql admin>startup variables>advanced networking and change the max_allowed_packet to 16M (or higher)

restart mysql and try the restore again.

Friday, 31 July 2009

MSSQL Linked server to MySQL

First download the connector:
http://dev.mysql.com/downloads/connector/odbc/5.1.html
Then the MySQL GUI tools
http://dev.mysql.com/downloads/gui-tools/5.0.html
install both on the MSSQL server

Go to the MySQL server a create a user:
mssqllink
Give them permissions to access, update etc the tables you need. To make sure they have remote access from another ip or hostname, right click on the user in the administrator and "add hostname". Fill in the hostname or IP of the MSSQL server.

Go back to the MSSQL server and connect to the MySQL server via MySQL Administrator. Use the username and the password you set for that user. If you can't connect then go back and check the user details on the MySQL server. No connection here, no connection from MSSQL

Go to the windows control panel>administrative tools>ODBC datasource and click on the system DSN tab. Click 'Add' and choose the MySQL ODBC driver - fill in the details with the username and password you used to connect from MySQL Administrator. Click test and it should come back ok. Save the datasource name so you can use it below.

Open SQL server management studio and go to Server objects>linked servers
Add a new linked server, choose the microsoft OLE DB provider for ODBC drivers Provider and fill in the details.

NOTE if this isn't present then you'll need to install it, for 64 bit servers MS has released it as a hotfix:

http://blogs.msdn.com/data/archive/2008/04/07/64-bit-oledb-provider-for-odbc-msdasql-is-now-available-for-windows-server-2003.aspx

Now on to the connection string. The connection string for MySQL connector 5.1 is:
Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;Database=myDataBase;User=myUsername; Password=myPassword;Option=3;
more info here: connectionstrings.com

Replace the myServerAddress, myUsername and myPassword as before for MySQL. Note i found that adding the database parameter caused it to fail, so if you have problems try omitting that one ("Database=;"). Finally add the name of the system DSN you created.

Phew! click ok and it will all work as expected. if not then check all the connections and things and make sure you can connect via MySQL administrator using that username and password.

to select data from the tables on the MySQL server you must use the
select * from OPENQUERY(LINKNAME,'Select * from x')
syntax as the connector doesn't support the 4 part name access. Get around this by using views in your MSSQL db of the MySQL tables.

Thursday, 18 June 2009

Coldfusion query error - INSERT failed because the following SET options have incorrect settings: 'ARITHABORT'

You can avoid this by setting your database options.
1. Right click your database
2. Click Properties
3. Click Options on the Left pane
4. Turn "Arithmetic Abort Enabled" to "True"

Execute your cfm page again and it should work properly

and info here: http://support.microsoft.com/kb/305333

Tuesday, 24 March 2009

ASP.NET control referencing in jquery

ASP.NET controls often render with client-side IDs different than what's declared in your aspx code.

If your using jquery the easiest way is to use the [attribute$=value] method - an example to get the aspx made link id, from your coded id:

//include jquery.js then:
$(document).ready(function(){$("a[id$='login_link']").click(function(event){tester(event,this)});});
function tester(event, el){
event.preventDefault();
alert($(el).attr("id"));
}

//for element:

Wednesday, 5 March 2008

Prototype.js get checked elements

To get the checked elements from a group of checkboxes you can use the select and css3 selectors shortcut:

var checked_el=surrounding_el.select('input:checked').each(function(checked_el) {
//do something with only the selected elements
alert("checked_element: "+checked_element.id);
});

/*
checked_el is a array holding the found elements
surrounding_el is a fieldset or div that encloses the checked boxes
select('input:checked') - select all with a CSS3 seletor type
of checked (http://www.w3.org/TR/css3-selectors/)
.each(function(checked_el) - loops on all the ones that are found
*/

Wednesday, 20 February 2008

google maps marker z index

Google have now prevented access to marker.setZIndex() (which was undocumented method anyway) A work around to get your marker to the top is:

function add_marker(){
var marker = new GMarker(point,{zIndexProcess:importanceOrder});
marker.importance = 2; //higher importance = higher marker z index
the_map.addOverlay(marker);
}

function importanceOrder (marker,b) {
return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance*1000000;
}

which moves the marker higher up - note you'll need to do this after you've added all the markers to the map. Otherwise the next z-index will continue after the last one you added (effectively cancelling out your increase in z-index)

Thursday, 24 January 2008

Coldfusion query column to array

The normal method of converting Coldfusion query column to array is to use a valuelist and list to array:

the_array=listtoarray("#valueList(the_query.the_column)#")

But this strips out any cells with empty strings in. To get around this use:

the_array=duplicate(the_query[column_name]);
ArrayPrepend(the_array,the_query[column_name][1]);

why the ArrayPrepend() call afterwards? Because CF arrays start at 1 and Java (the underlying language) starts at 0, so the duplicate function misses off the first row of the column.

nice.