Created
September 27, 2013 22:21
-
-
Save darrenkopp/6736052 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Data.Odbc; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using System.Xml.Serialization; | |
namespace ConsoleApplication2 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Scanning..."); | |
const string path = @"\\sage-300cre-vm\timberline office\data\construction sample data"; | |
try | |
{ | |
//using (var connection = (IDbConnection)(Activator.CreateInstance(Assembly.LoadWithPartialName("Pervasive.Data.SqlClient").GetType("Pervasive.Data.SqlClient.PsqlConnection")))) | |
using (var connection = new OdbcConnection(string.Format(@"Provider=MSDASQL.1;Driver={{Timberline Data}};DBQ={0};uid={1};pwd={2};codepage=1252;dictionarymode=1;standardmode=0;maxcolsupport=1500;databasetype=1", path, "", ""))) | |
//using (var connection = new OdbcConnection(@"Driver={Pervasive ODBC Client Interface};DBQ=\\sage-300cre-vm\timberline office\data\construction sample data;")) | |
{ | |
//connection.ConnectionString = string.Format("DBQ={0};", path); | |
connection.Open(); | |
//using (var schema = connection.GetSchema("Tables")) | |
//{ | |
// var serializer = new XmlSerializer(typeof(DataTable)); | |
// using (var stream = File.Create("tables.xml")) | |
// serializer.Serialize(stream, schema); | |
// //Parse(schema); | |
//} | |
DumpTables(connection, "ts_ctl_record_1", "ts_ctl_record_2", "ts_ctl_record_3", "ts_ctl_record_4", "ts_ctl_record_5"); | |
connection.Close(); | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("FAIL {0}", ex.Message); | |
} | |
//Console.Read(); | |
} | |
private static void DumpTables(IDbConnection connection, params string[] tables) | |
{ | |
foreach (var table in tables) | |
{ | |
Console.WriteLine("Dumping {0}", table); | |
using (var s = File.Create(string.Format("{0}.txt", table))) | |
{ | |
using (var output = new StreamWriter(s)) | |
{ | |
using (var command = connection.CreateCommand()) | |
{ | |
command.CommandText = string.Format(@"SELECT * FROM {0}", table); | |
using (var reader = command.ExecuteReader()) | |
{ | |
while (reader.Read()) | |
{ | |
for (int i = 0; i < reader.FieldCount; i++) | |
{ | |
output.WriteLine("{0}: {1}", reader.GetName(i), reader.GetValue(i)); | |
} | |
output.WriteLine(); | |
output.WriteLine(); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
private static void Parse(DataTable table) | |
{ | |
foreach (DataRow row in table.Rows) | |
{ | |
foreach (DataColumn col in table.Columns) | |
{ | |
var value = row.ItemArray[col.Ordinal]; | |
if (value is DataTable) | |
{ | |
Parse(value as DataTable); | |
} | |
else | |
{ | |
Console.WriteLine("{0}: {1}", col.ColumnName, row.ItemArray[col.Ordinal]); | |
} | |
} | |
Console.WriteLine("--------------"); | |
Console.WriteLine(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment