Migrating data from Access 97 to Postgres database
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

68 wiersze
2.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Renci.SshNet;
  6. using Npgsql;
  7. namespace acc_pgsql
  8. {
  9. public static class PGSqlHelper
  10. {
  11. static string _ipaddress = "192.168.0.108";
  12. static string _username = "mcarman";
  13. static string _pwd = "@ng31F@rm0823262";
  14. static string _localip = "127.0.0.1";
  15. static uint _port = (uint)5432;
  16. static string _connString = "Server={0};Database=accessdb_v2;Port={1};User Id={2};Password={3};";
  17. public static System.Data.DataSet RunPGSql( List<string> sql)
  18. {
  19. uint port = (uint)_port;
  20. using (SshClient client = new SshClient(_ipaddress, _username, _pwd))
  21. {
  22. System.Data.DataSet ds = new System.Data.DataSet();
  23. client.Connect();
  24. ForwardedPortLocal tunnel = new ForwardedPortLocal(_localip, _localip, _port);
  25. client.AddForwardedPort(tunnel);
  26. if (client.IsConnected)
  27. {
  28. tunnel.Start();
  29. string connStr = string.Format(_connString, tunnel.BoundHost, tunnel.BoundPort, _username, _pwd);
  30. try
  31. {
  32. using (NpgsqlConnection conn = new NpgsqlConnection(connStr))
  33. {
  34. conn.Open();
  35. NpgsqlCommand cmd = conn.CreateCommand();
  36. cmd.CommandType = System.Data.CommandType.Text;
  37. foreach (string s in sql)
  38. {
  39. System.Data.DataTable tbl = new System.Data.DataTable();
  40. cmd.CommandText = s;
  41. NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(cmd);
  42. adapter.Fill(tbl);
  43. ds.Tables.Add(tbl);
  44. }
  45. return ds;
  46. }
  47. }
  48. catch (Exception ex)
  49. {
  50. Console.WriteLine(ex.Message);
  51. throw ex;
  52. }
  53. }
  54. else
  55. {
  56. return ds;
  57. //kill program
  58. }
  59. }
  60. }
  61. }
  62. }