|
|
|
@@ -1,16 +1,10 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using System.Data.OleDb;
|
|
|
|
|
using Volian.Base.Library;
|
|
|
|
|
|
|
|
|
|
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
|
|
|
|
|
|
|
|
|
@@ -33,25 +27,11 @@ namespace RoAccessToSql
|
|
|
|
|
public partial class RoAccessToSql : Form
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
private string _MSAccessPath = null;
|
|
|
|
|
public string MSAccessPath
|
|
|
|
|
{
|
|
|
|
|
get { return _MSAccessPath; }
|
|
|
|
|
set { _MSAccessPath = value; }
|
|
|
|
|
}
|
|
|
|
|
private string _SqlServerName = null;
|
|
|
|
|
public string SqlServerName
|
|
|
|
|
{
|
|
|
|
|
get { return _SqlServerName; }
|
|
|
|
|
set { _SqlServerName = value; }
|
|
|
|
|
}
|
|
|
|
|
private string _SqlDatabaseName = null;
|
|
|
|
|
public string SqlDatabaseName
|
|
|
|
|
{
|
|
|
|
|
get { return _SqlDatabaseName; }
|
|
|
|
|
set { _SqlDatabaseName = value; }
|
|
|
|
|
}
|
|
|
|
|
bool _Initializing = false;
|
|
|
|
|
|
|
|
|
|
public string MSAccessPath { get; set; } = null;
|
|
|
|
|
public string SqlServerName { get; set; } = null;
|
|
|
|
|
public string SqlDatabaseName { get; set; } = null;
|
|
|
|
|
readonly bool _Initializing = false;
|
|
|
|
|
|
|
|
|
|
public RoAccessToSql(string[] args)
|
|
|
|
|
{
|
|
|
|
@@ -66,7 +46,7 @@ namespace RoAccessToSql
|
|
|
|
|
}
|
|
|
|
|
else if (parm.StartsWith("/sqldb="))
|
|
|
|
|
{
|
|
|
|
|
SqlDatabaseName = parm.Substring(7) + "_RO";
|
|
|
|
|
SqlDatabaseName = $"{parm.Substring(7)}_RO";
|
|
|
|
|
}
|
|
|
|
|
else if (parm.StartsWith("/server="))
|
|
|
|
|
{
|
|
|
|
@@ -92,7 +72,7 @@ namespace RoAccessToSql
|
|
|
|
|
if (UserInRoEditor()) this.Close();
|
|
|
|
|
tbSqlDbName.Text = SqlDatabaseName;
|
|
|
|
|
_TmpFileForConnectStr = Path.GetTempPath();
|
|
|
|
|
_TmpFileForConnectStr = _TmpFileForConnectStr + @"\PromsConnect.txt";
|
|
|
|
|
_TmpFileForConnectStr += @"\PromsConnect.txt";
|
|
|
|
|
File.Delete(_TmpFileForConnectStr);
|
|
|
|
|
_Initializing = false;
|
|
|
|
|
}
|
|
|
|
@@ -100,10 +80,10 @@ namespace RoAccessToSql
|
|
|
|
|
private bool UserInRoEditor()
|
|
|
|
|
{
|
|
|
|
|
FileInfo fiown = null;
|
|
|
|
|
FileStream fsown = null;
|
|
|
|
|
// The following code was taken from the roeditor. It uses the 'RoEditor.own' file to assure that
|
|
|
|
|
// no one is in the roeditor. This file is located in the microsoft access database directory.
|
|
|
|
|
try
|
|
|
|
|
FileStream fsown;
|
|
|
|
|
// The following code was taken from the roeditor. It uses the 'RoEditor.own' file to assure that
|
|
|
|
|
// no one is in the roeditor. This file is located in the microsoft access database directory.
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string filename = MSAccessPath + @"\RoEditor.own";
|
|
|
|
|
fiown = new FileInfo(filename);
|
|
|
|
@@ -119,7 +99,7 @@ namespace RoAccessToSql
|
|
|
|
|
fsown = fiown.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
|
|
|
|
TextReader tr1 = new StreamReader(fsown);
|
|
|
|
|
string who1 = tr1.ReadToEnd();
|
|
|
|
|
MessageBox.Show(ex.Message + "\r\n\r\n" + who1, "RO Editor In Use", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
MessageBox.Show($"{ex.Message}\r\n\r\n{who1}", "RO Editor In Use", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
}
|
|
|
|
|
fsown = fiown.Open(FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
|
|
|
|
|
TextReader tr = new StreamReader(fsown);
|
|
|
|
@@ -142,8 +122,8 @@ namespace RoAccessToSql
|
|
|
|
|
tw.WriteLine("Current User: {0}, Date and Time Started: {1}", Environment.UserName.ToUpper(), DateTime.Now.ToString("MM/dd/yyyy @ hh:mm"));
|
|
|
|
|
tw.Flush();
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
catch (IOException)
|
|
|
|
|
{
|
|
|
|
|
fsown = fiown.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
|
|
|
|
TextReader tr = new StreamReader(fsown);
|
|
|
|
|
string who = tr.ReadToEnd();
|
|
|
|
@@ -154,25 +134,20 @@ namespace RoAccessToSql
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
static string _ErrorLogFileName;
|
|
|
|
|
public static string ErrorLogFileName
|
|
|
|
|
{
|
|
|
|
|
get { return _ErrorLogFileName; }
|
|
|
|
|
set { _ErrorLogFileName = value; }
|
|
|
|
|
}
|
|
|
|
|
// make error log file name (uses same logic as proms error log)
|
|
|
|
|
static bool ChangeLogFileName(string AppenderName, string NewFilename)
|
|
|
|
|
|
|
|
|
|
public static string ErrorLogFileName { get; set; }
|
|
|
|
|
// make error log file name (uses same logic as proms error log)
|
|
|
|
|
static bool ChangeLogFileName(string AppenderName, string NewFilename)
|
|
|
|
|
{
|
|
|
|
|
log4net.Repository.ILoggerRepository RootRep;
|
|
|
|
|
RootRep = log4net.LogManager.GetRepository();
|
|
|
|
|
foreach (log4net.Appender.IAppender iApp in RootRep.GetAppenders())
|
|
|
|
|
{
|
|
|
|
|
if (iApp.Name.CompareTo(AppenderName) == 0
|
|
|
|
|
&& iApp is log4net.Appender.FileAppender)
|
|
|
|
|
{
|
|
|
|
|
log4net.Appender.FileAppender fApp = (log4net.Appender.FileAppender)iApp;
|
|
|
|
|
&& iApp is log4net.Appender.FileAppender fApp)
|
|
|
|
|
{
|
|
|
|
|
string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
|
|
fApp.File = folderPath + @"\VEPROMS\" + (Volian.Base.Library.VlnSettings.GetCommand("prefix", "") + "_").TrimStart("_".ToCharArray()) + NewFilename;
|
|
|
|
|
fApp.File = $@"{folderPath}\VEPROMS\{($"{Volian.Base.Library.VlnSettings.GetCommand("prefix", "")}_").TrimStart("_".ToCharArray())}{NewFilename}";
|
|
|
|
|
ErrorLogFileName = fApp.File;
|
|
|
|
|
fApp.ActivateOptions();
|
|
|
|
|
return true;
|
|
|
|
@@ -189,7 +164,7 @@ namespace RoAccessToSql
|
|
|
|
|
if (Directory.Exists(fbd.SelectedPath))
|
|
|
|
|
tbAccessPath.Text = fbd.SelectedPath;
|
|
|
|
|
else
|
|
|
|
|
MessageBox.Show("Path doesn't exist " + tbAccessPath.Text);
|
|
|
|
|
MessageBox.Show($"Path doesn't exist {tbAccessPath.Text}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Convert the data
|
|
|
|
@@ -212,7 +187,7 @@ namespace RoAccessToSql
|
|
|
|
|
{
|
|
|
|
|
DateTime dtSunday = DateTime.Now.AddDays(-((int)DateTime.Now.DayOfWeek));
|
|
|
|
|
|
|
|
|
|
ChangeLogFileName("LogFileAppender", SqlDatabaseName + " " + dtSunday.ToString("yyyyMMdd") + " ErrorLog.txt");
|
|
|
|
|
ChangeLogFileName("LogFileAppender", $"{SqlDatabaseName} {dtSunday:yyyyMMdd} ErrorLog.txt");
|
|
|
|
|
_MyLog.InfoFormat("\r\nSession Beginning\r\n<===={0}[SQL:{1:yyMM.ddHH}]====== User: {2}/{3} Started {4} ===============>{5}"
|
|
|
|
|
, Application.ProductVersion, RevDate, DateTime.Now, Environment.UserDomainName, Environment.UserName, DateTime.Now.ToString("dddd MMMM d, yyyy h:mm:ss tt"), "");
|
|
|
|
|
}
|
|
|
|
@@ -229,7 +204,7 @@ namespace RoAccessToSql
|
|
|
|
|
if (sqlConnection.State == ConnectionState.Open)
|
|
|
|
|
{
|
|
|
|
|
// now try to open access db:
|
|
|
|
|
string strDatabaseConnectionCommand = "Provider=Microsoft.ACE.OLEDB.12.0;Password=\"\";User ID=Admin;Data Source=" + MSAccessPath + "\\ROMaster.mdb;Mode=Share Deny None;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
|
|
|
|
|
string strDatabaseConnectionCommand = $"Provider=Microsoft.ACE.OLEDB.12.0;Password=\"\";User ID=Admin;Data Source={MSAccessPath}\\ROMaster.mdb;Mode=Share Deny None;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
|
|
|
|
|
using (OleDbConnection accessConnection = new OleDbConnection(strDatabaseConnectionCommand))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -251,13 +226,13 @@ namespace RoAccessToSql
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_MyLog.Error("SQL Connection is not open. Check connection string: " + tbSqlDbName.Text);
|
|
|
|
|
MessageBox.Show("Check connection string: " + tbSqlDbName.Text, "SQL Connection is not open.");
|
|
|
|
|
_MyLog.Error($"SQL Connection is not open. Check connection string: {tbSqlDbName.Text}");
|
|
|
|
|
MessageBox.Show($"Check connection string: {tbSqlDbName.Text}", "SQL Connection is not open.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (SqlException ex)
|
|
|
|
|
{
|
|
|
|
|
_MyLog.Error("SQL Connection is not open. Check connection string: " + tbSqlDbName.Text);
|
|
|
|
|
_MyLog.Error($"SQL Connection is not open. Check connection string: {tbSqlDbName.Text}");
|
|
|
|
|
MessageBox.Show(ex.Message, "Unknown error when migrating RO data from MS Access to SQL");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -274,11 +249,10 @@ namespace RoAccessToSql
|
|
|
|
|
lastTimeDbs = ProgressBarUpdate(pBarDbs, null, 0, 1, 0, 0, lastTimeDbs, false);
|
|
|
|
|
lastTimeRos = ProgressBarUpdate(pBarROs, null, 0, maxCntRo, 0, 0, lastTimeRos, false);
|
|
|
|
|
lastTimeDbs = ProgressBarUpdate(pBarDbs, "ROMaster Table", 0, 5, 0, 1, lastTimeDbs, false);
|
|
|
|
|
OleDbDataReader reader = null;
|
|
|
|
|
OleDbCommand command = new OleDbCommand("select * from ROMaster", accessConnection);
|
|
|
|
|
reader = command.ExecuteReader();
|
|
|
|
|
// Do access's romaster table first so that the list of other tables to process is found. While doing this, migrate this table's data.
|
|
|
|
|
int cntRo = 0;
|
|
|
|
|
OleDbCommand command = new OleDbCommand("select * from ROMaster", accessConnection);
|
|
|
|
|
OleDbDataReader reader = command.ExecuteReader();
|
|
|
|
|
// Do access's romaster table first so that the list of other tables to process is found. While doing this, migrate this table's data.
|
|
|
|
|
int cntRo = 0;
|
|
|
|
|
int cntDb = 0;
|
|
|
|
|
int maxCntDb = 0;
|
|
|
|
|
while (reader.Read()) // reading from Access Database
|
|
|
|
@@ -303,13 +277,12 @@ namespace RoAccessToSql
|
|
|
|
|
maxCntDb++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lastTimeRos = ProgressBarUpdate(pBarROs, "ROMaster", 0, maxCntRo, maxCntRo, 1, lastTimeRos, true);
|
|
|
|
|
ProgressBarUpdate(pBarROs, "ROMaster", 0, maxCntRo, maxCntRo, 1, lastTimeRos, true);
|
|
|
|
|
lastTimeDbs = ProgressBarUpdate(pBarDbs, null, 0, maxCntDb, 0, 0, lastTimeDbs, false);
|
|
|
|
|
reader.Close();
|
|
|
|
|
reader = null;
|
|
|
|
|
|
|
|
|
|
// now migrate all the tables that were found
|
|
|
|
|
foreach (string tableName in allTables)
|
|
|
|
|
|
|
|
|
|
// now migrate all the tables that were found
|
|
|
|
|
foreach (string tableName in allTables)
|
|
|
|
|
{
|
|
|
|
|
lastTimeRos = DateTime.Now;
|
|
|
|
|
cntRo = 0;
|
|
|
|
@@ -318,7 +291,7 @@ namespace RoAccessToSql
|
|
|
|
|
lastTimeRos = ProgressBarUpdate(pBarROs, null, 0, maxCntRo, 0, 0, lastTimeRos, true);
|
|
|
|
|
lastTimeDbs = ProgressBarUpdate(pBarDbs, allTablesText[cntDb], 0, maxCntDb, cntDb, 1, lastTimeDbs, false);
|
|
|
|
|
command = null;
|
|
|
|
|
command = new OleDbCommand("select * from " + tableName, accessConnection);
|
|
|
|
|
command = new OleDbCommand($"select * from {tableName}", accessConnection);
|
|
|
|
|
reader = command.ExecuteReader();
|
|
|
|
|
while (reader.Read()) // read all of the records from the current access table
|
|
|
|
|
{
|
|
|
|
@@ -338,7 +311,7 @@ namespace RoAccessToSql
|
|
|
|
|
reader = null;
|
|
|
|
|
lastTimeRos = ProgressBarUpdate(pBarROs, tableName, 0, maxCntRo, maxCntRo, 1, lastTimeRos, false);
|
|
|
|
|
}
|
|
|
|
|
lastTimeDbs = ProgressBarUpdate(pBarDbs, allTablesText[maxCntDb - 1], 0, maxCntDb, maxCntDb, 1, lastTimeDbs, false);
|
|
|
|
|
ProgressBarUpdate(pBarDbs, allTablesText[maxCntDb - 1], 0, maxCntDb, maxCntDb, 1, lastTimeDbs, false);
|
|
|
|
|
pBarDbs.Text = "Referenced Object Tables Migration Completed";
|
|
|
|
|
pBarROs.Text = "Referenced Objects Migration Completed";
|
|
|
|
|
btnConvert.Enabled = false;
|
|
|
|
@@ -357,7 +330,7 @@ namespace RoAccessToSql
|
|
|
|
|
string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
|
|
|
|
|
string strInsert = "INSERT INTO ROMaster (RecID, RecType, ModDateTime, Info) ";
|
|
|
|
|
// note that '8' for rectype flags database converted:
|
|
|
|
|
strInsert = strInsert + " VALUES ('09999999', 8, '" + dt + "', '" + _SqlConnectStr + "');";
|
|
|
|
|
strInsert = $"{strInsert} VALUES ('09999999', 8, '{dt}', '{_SqlConnectStr}');";
|
|
|
|
|
OleDbCommand command = new OleDbCommand(strInsert, accessConnection);
|
|
|
|
|
reader = command.ExecuteReader();
|
|
|
|
|
if (reader.Read()) return;
|
|
|
|
@@ -367,7 +340,7 @@ namespace RoAccessToSql
|
|
|
|
|
MessageBox.Show(e.Message, "Error on insert to flag migration completed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private string _TmpFileForConnectStr = null;
|
|
|
|
|
private readonly string _TmpFileForConnectStr = null;
|
|
|
|
|
private void WriteSqlPathToTempFile()
|
|
|
|
|
{
|
|
|
|
|
System.IO.File.WriteAllText(_TmpFileForConnectStr, _SqlConnectStr);
|
|
|
|
@@ -375,13 +348,12 @@ namespace RoAccessToSql
|
|
|
|
|
// the following is used to update the progress bars, it finds how many records are in a table.
|
|
|
|
|
private int GetRecordCountForTable(string tableName, OleDbConnection accessConnection)
|
|
|
|
|
{
|
|
|
|
|
OleDbDataReader reader = null;
|
|
|
|
|
int retcnt = 100;
|
|
|
|
|
int retcnt = 100;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
OleDbCommand command = new OleDbCommand("SELECT COUNT (RecID) as cnt FROM " + tableName, accessConnection);
|
|
|
|
|
reader = command.ExecuteReader();
|
|
|
|
|
if (reader.Read())
|
|
|
|
|
OleDbCommand command = new OleDbCommand($"SELECT COUNT (RecID) as cnt FROM {tableName}", accessConnection);
|
|
|
|
|
OleDbDataReader reader = command.ExecuteReader();
|
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
retcnt = reader.GetInt32(0);
|
|
|
|
|
}
|
|
|
|
@@ -393,7 +365,8 @@ namespace RoAccessToSql
|
|
|
|
|
}
|
|
|
|
|
return retcnt;
|
|
|
|
|
}
|
|
|
|
|
DateTime ProgressBarUpdate(DevComponents.DotNetBar.Controls.ProgressBarX pbi, string msg, int min, int max, int progress, int flag, DateTime lastUpdateDisplay, bool doTimeCheck)
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping min for Debugging")]
|
|
|
|
|
DateTime ProgressBarUpdate(DevComponents.DotNetBar.Controls.ProgressBarX pbi, string msg, int min, int max, int progress, int flag, DateTime lastUpdateDisplay, bool doTimeCheck)
|
|
|
|
|
{
|
|
|
|
|
if (flag == 0) // setup
|
|
|
|
|
pbi.Maximum = max;
|
|
|
|
@@ -412,11 +385,13 @@ namespace RoAccessToSql
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SqlCommand command = new SqlCommand();
|
|
|
|
|
command.Connection = sqlConnection;
|
|
|
|
|
command.CommandType = CommandType.StoredProcedure;
|
|
|
|
|
command.CommandText = "insertAllRectypes";
|
|
|
|
|
command.Parameters.AddWithValue("@RecType", RecType);
|
|
|
|
|
SqlCommand command = new SqlCommand
|
|
|
|
|
{
|
|
|
|
|
Connection = sqlConnection,
|
|
|
|
|
CommandType = CommandType.StoredProcedure,
|
|
|
|
|
CommandText = "insertAllRectypes"
|
|
|
|
|
};
|
|
|
|
|
command.Parameters.AddWithValue("@RecType", RecType);
|
|
|
|
|
if (AccPageID == null || AccPageID == "")
|
|
|
|
|
command.Parameters.AddWithValue("@AccPageID", string.Empty);
|
|
|
|
|
else
|
|
|
|
@@ -428,9 +403,8 @@ namespace RoAccessToSql
|
|
|
|
|
command.Parameters.AddWithValue("@ModDateTime", ModDateTime);
|
|
|
|
|
using (SqlDataReader reader = command.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
bool success = true;
|
|
|
|
|
}
|
|
|
|
|
command = null;
|
|
|
|
|
}
|
|
|
|
|
command = null;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@@ -438,32 +412,15 @@ namespace RoAccessToSql
|
|
|
|
|
_MyLog.Error(msg, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
// the user selected the button to test the sql connection string
|
|
|
|
|
private void btnTestConnect_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TestConnection(true);
|
|
|
|
|
}
|
|
|
|
|
// the RevDate & RevDescription are found in a stored procedure, vesp_GetSQLCodeRevision, in the sql database. These get updated each
|
|
|
|
|
// time a revision is made to the sql database using ROFixes.sql script.
|
|
|
|
|
private static DateTime _RevDate = DateTime.MinValue;
|
|
|
|
|
public static DateTime RevDate
|
|
|
|
|
{
|
|
|
|
|
get { return _RevDate; }
|
|
|
|
|
set { _RevDate = value; }
|
|
|
|
|
}
|
|
|
|
|
private static string _RevDescription = "Unknown";
|
|
|
|
|
public static string RevDescription
|
|
|
|
|
{
|
|
|
|
|
get { return _RevDescription; }
|
|
|
|
|
set { _RevDescription = value; }
|
|
|
|
|
}
|
|
|
|
|
// This is called to test the sql connection, either from the button when pressed by user, or from the convert button, before
|
|
|
|
|
// the conversion is done. See below for what is checked
|
|
|
|
|
private bool TestConnection(bool notifyUser)
|
|
|
|
|
private void btnExit_Click(object sender, EventArgs e) => this.Close();
|
|
|
|
|
// the user selected the button to test the sql connection string
|
|
|
|
|
private void btnTestConnect_Click(object sender, EventArgs e) => TestConnection(true);
|
|
|
|
|
|
|
|
|
|
public static DateTime RevDate { get; set; } = DateTime.MinValue;
|
|
|
|
|
public static string RevDescription { get; set; } = "Unknown";
|
|
|
|
|
// This is called to test the sql connection, either from the button when pressed by user, or from the convert button, before
|
|
|
|
|
// the conversion is done. See below for what is checked
|
|
|
|
|
private bool TestConnection(bool notifyUser)
|
|
|
|
|
{
|
|
|
|
|
// The following conditions must be true in order to migrate the ro data to sql. Only the first condition can be
|
|
|
|
|
// tested in this executable since the roall database is interfaced to by the roeditor & the program that migrates the data.
|
|
|
|
@@ -485,12 +442,14 @@ namespace RoAccessToSql
|
|
|
|
|
connection.Open();
|
|
|
|
|
if (connection.State == ConnectionState.Open)
|
|
|
|
|
{
|
|
|
|
|
// now see if there is an roall table
|
|
|
|
|
SqlCommand command = new SqlCommand();
|
|
|
|
|
command.Connection = connection;
|
|
|
|
|
command.CommandType = CommandType.Text;
|
|
|
|
|
command.CommandText = "(SELECT count(*) FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ROALL]') AND type in (N'U'))";
|
|
|
|
|
using (SqlDataReader reader = command.ExecuteReader())
|
|
|
|
|
// now see if there is an roall table
|
|
|
|
|
SqlCommand command = new SqlCommand
|
|
|
|
|
{
|
|
|
|
|
Connection = connection,
|
|
|
|
|
CommandType = CommandType.Text,
|
|
|
|
|
CommandText = "(SELECT count(*) FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ROALL]') AND type in (N'U'))"
|
|
|
|
|
};
|
|
|
|
|
using (SqlDataReader reader = command.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
@@ -509,11 +468,13 @@ namespace RoAccessToSql
|
|
|
|
|
{
|
|
|
|
|
// now see if there are stored procedures:
|
|
|
|
|
command = null; // reset command
|
|
|
|
|
command = new SqlCommand();
|
|
|
|
|
command.Connection = connection;
|
|
|
|
|
command.CommandType = CommandType.Text;
|
|
|
|
|
command.CommandText = "(SELECT count(*) FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[deleteByROTable]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)";
|
|
|
|
|
using (SqlDataReader reader = command.ExecuteReader())
|
|
|
|
|
command = new SqlCommand
|
|
|
|
|
{
|
|
|
|
|
Connection = connection,
|
|
|
|
|
CommandType = CommandType.Text,
|
|
|
|
|
CommandText = "(SELECT count(*) FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[deleteByROTable]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)"
|
|
|
|
|
};
|
|
|
|
|
using (SqlDataReader reader = command.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
@@ -533,11 +494,13 @@ namespace RoAccessToSql
|
|
|
|
|
{
|
|
|
|
|
// now test that the roall table is empty:
|
|
|
|
|
command = null; // reset command
|
|
|
|
|
command = new SqlCommand();
|
|
|
|
|
command.Connection = connection;
|
|
|
|
|
command.CommandType = CommandType.Text;
|
|
|
|
|
command.CommandText = "SELECT count(*) FROM roall";
|
|
|
|
|
using (SqlDataReader reader = command.ExecuteReader())
|
|
|
|
|
command = new SqlCommand
|
|
|
|
|
{
|
|
|
|
|
Connection = connection,
|
|
|
|
|
CommandType = CommandType.Text,
|
|
|
|
|
CommandText = "SELECT count(*) FROM roall"
|
|
|
|
|
};
|
|
|
|
|
using (SqlDataReader reader = command.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
@@ -557,16 +520,18 @@ namespace RoAccessToSql
|
|
|
|
|
{
|
|
|
|
|
// now test that the database version is ok
|
|
|
|
|
command = null; // reset command
|
|
|
|
|
command = new SqlCommand();
|
|
|
|
|
command.Connection = connection;
|
|
|
|
|
command.CommandType = CommandType.StoredProcedure;
|
|
|
|
|
command.CommandText = "vesp_GetSQLCodeRevision";
|
|
|
|
|
using (SqlDataReader reader = command.ExecuteReader())
|
|
|
|
|
command = new SqlCommand
|
|
|
|
|
{
|
|
|
|
|
Connection = connection,
|
|
|
|
|
CommandType = CommandType.StoredProcedure,
|
|
|
|
|
CommandText = "vesp_GetSQLCodeRevision"
|
|
|
|
|
};
|
|
|
|
|
using (SqlDataReader reader = command.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
_RevDate = reader.GetDateTime(0);
|
|
|
|
|
_RevDescription = reader.GetString(1);
|
|
|
|
|
RevDate = reader.GetDateTime(0);
|
|
|
|
|
RevDescription = reader.GetString(1);
|
|
|
|
|
dbsuc = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@@ -582,13 +547,13 @@ namespace RoAccessToSql
|
|
|
|
|
}
|
|
|
|
|
catch (SqlException ex)
|
|
|
|
|
{
|
|
|
|
|
if (notifyUser) MessageBox.Show("Connection failed: " + ex, "Connection Failed");
|
|
|
|
|
if (notifyUser) MessageBox.Show($"Connection failed: {ex}", "Connection Failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
if (notifyUser) MessageBox.Show("Connection failed: " + ex, "Connection Failed");
|
|
|
|
|
if (notifyUser) MessageBox.Show($"Connection failed: {ex}", "Connection Failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (notifyUser && success) MessageBox.Show("You have been successfully connected to the database!", "Connection Succeeded");
|
|
|
|
|