Recently one of my machines crashed which was the only local machine that had a certain MSSQL database on it. It's a rather old and unused system, but missed greatly when it's not working.
For whatever reason that I won't get into here I had an issue with an ISP where I couldn't get access to my database to copy it back locally. This really annoyed me but I was determined not to let this beat me.
I still had access to the site where I had created a SQL console (a page where I could enter SQL code and it would get executed). I decided that I could use this to query the database and then with this data I could create a script to create the database locally.
Here is the SQL console:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SQL Console</title>
<link rel="stylesheet" href="sql_console.css" type="text/css">
</head>
<cfif IsDefined("FORM.SQL")>
<!--- Execute submitted SQL statement --->
<cftry>
<cfquery name="SQL" datasource="#dbdatasource#">
#PreserveSingleQuotes(FORM.SQL)#
</cfquery>
<cfcatch>
<cfset ErrorMessage = "#CFCATCH.message#<br>#CFCATCH.detail#">
</cfcatch>
</cftry>
</cfif>
<body style="margin:5px"><cfoutput>
<form name="console" action="console.cfm" method="post">
<table border="0" cellpadding="4" cellspacing="1" bgcolor="##000000" width="100%">
<!--- SQL input --->
<tr>
<td bgcolor="##99CCCC" valign="top">SQL</td>
<td bgcolor="##FFFF99" colspan="2" valign="top"><textarea name="sql" cols="100" rows="10"><cfif IsDefined("FORM.SQL")>#FORM.SQL#</cfif></textarea> <input type="submit" value=" Run > "></td>
</tr>
<!--- SQL messages/errors --->
<tr>
<td bgcolor="##99CCCC" rowspan="2" valign="top">Messages</td>
<td bgcolor="##CCFFCC" valign="top">Messages</td>
<td bgcolor="##CCFFCC" valign="top">Errors</td>
</tr>
<tr>
<td bgcolor="##FFFFCC" valign="top" width="50%">
<cfif IsDefined("FORM.SQL") and not IsDefined("ErrorMessage")>
Query executed successfully
<cfif IsDefined("SQL.RecordCount")><br>#SQL.RecordCount# records returned/processed</cfif>
<cfelse>
</cfif>
</td>
<td bgcolor="##FFFFCC" valign="top" width="50%">
<cfif IsDefined("ErrorMessage")>
#ErrorMessage#
<cfelse>
</cfif>
</td>
</tr>
<!--- SQL results --->
<tr>
<td bgcolor="##99CCCC" valign="top">Results</td>
<td bgcolor="##006699" colspan="2" valign="top">
<cfif IsDefined("FORM.SQL") and IsDefined("SQL.ColumnList")>
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<cfloop index="col" from="1" to="#ListLen(SQL.ColumnList)#"><td bgcolor="##006699">#ListGetAt('#SQL.ColumnList#', col)#</td></cfloop>
</tr>
<cfset bgcolor="006699">
<cfloop query="SQL">
<tr>
<cfloop index="col" from="1" to="#ListLen(SQL.ColumnList)#"><td bgcolor="###bgcolor#">#Evaluate("SQL.#ListGetAt('#SQL.ColumnList#', col)#")#</td></cfloop>
</td>
</tr>
<cfset bgcolor=Iif(bgcolor eq "006699", DE("003366"), DE("006699"))>
</cfloop>
</table>
</cfif>
</td>
</tr>
</table>
</form>
</cfoutput></body>
</html>
With this is place I ran the query to extract the database data for the tables:
[More]