Posts Tagged ‘Migrate’

Migrate data from MySQL to SQL Server

September 13th, 2009

Since I work with MS SQL Server (and have done for the last 10 years) I converted the MySQL-databases in MSure to MS SQL.
This script will copy 4 tables, easy to add more.
Remember to change the ConnectionString’s to your settings. (server, database, user and password)

Set oMySQL = createobject("ADODB.Connection")
oMySQL.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;DATABASE=msure;UID=msure;PWD=abc123; OPTION=3"
oMySQL.Open

Set oSql = createobject("ADODB.Connection")
oSql.ConnectionString = "DRIVER={SQL Server Native Client 10.0};SERVER=localhost;DATABASE=msure;UID=MSure;PWD=abc123; OPTION=3"
oSql.Open

CopyTable "UtomhusNorr"
CopyTable "UtomhusOster"
CopyTable "UtomhusSoder"
CopyTable "UtomhusVaster"

sub CopyTable(sTable)
  set oSource = oMySQL.Execute("SELECT * FROM " & sTable)
  do while not oSource.Eof

    sSql = "INSERT INTO " & sTable & " (TimeStamp, Temperature) VALUES ('" & oSource("TimeStamp") & "', '" & Replace(oSource("Temperature"),",", ".") & "')"

    wscript.echo sSql
    oSql.Execute sSql

    oSource.MoveNext
  Loop
End Sub

oMySQL.Close
oSql.Close