27 |
private SqlCommand sqlCmd = new SqlCommand(); |
private SqlCommand sqlCmd = new SqlCommand(); |
28 |
|
|
29 |
const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser"; |
const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser"; |
30 |
|
const Version CURRENT_DB_VERSION = new Version(1, 0, 0, 3); |
31 |
public static string InstanceName |
public static string InstanceName |
32 |
{ |
{ |
33 |
get |
get |
52 |
|
|
53 |
Logging.ATSAdminLog.Debug("SetupDatabase() called "); |
Logging.ATSAdminLog.Debug("SetupDatabase() called "); |
54 |
try |
try |
55 |
{ |
{ |
56 |
sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString; |
sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString; |
57 |
|
using (log4net.NDC.Push(string.Format("ConnectionString={0}", Properties.Settings.Default.atsConnectionString))) |
58 |
|
{ |
59 |
|
Logging.ATSAdminLog.Debug("Opening connection to AnywhereTS Database"); |
60 |
|
} |
61 |
sqlCon.Open(); |
sqlCon.Open(); |
62 |
} |
} |
63 |
catch |
catch |
67 |
//bCreateDB = true; |
//bCreateDB = true; |
68 |
try |
try |
69 |
{ |
{ |
70 |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
using (log4net.NDC.Push(string.Format("SQL Statment={0}", Resource1.CreateDatabase.ToString()))) |
71 |
sqlCon.Open(); |
{ |
72 |
RunScript(Resource1.CreateDatabase.ToString()); |
Logging.ATSAdminLog.Debug("Creating Database AnywhereTS"); |
73 |
sqlCon.Close(); |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
74 |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
sqlCon.Open(); |
75 |
sqlCon.Open(); |
RunScript(Resource1.CreateDatabase.ToString()); |
76 |
RunScript(Resource1.CreateTables.ToString()); |
sqlCon.Close(); |
77 |
sqlCon.Close(); |
} |
78 |
//sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString); |
Logging.ATSAdminLog.Debug("Created Database AnywhereTS"); |
79 |
//sqlCon.Open(); |
|
80 |
|
using (log4net.NDC.Push(string.Format("SQL Statment={0}", Resource1.CreateTables.ToString()))) |
81 |
|
{ |
82 |
|
Logging.ATSAdminLog.Debug("Creating Tables in AnywhereTS Database"); |
83 |
|
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
84 |
|
sqlCon.Open(); |
85 |
|
RunScript(Resource1.CreateTables.ToString()); |
86 |
|
sqlCon.Close(); |
87 |
|
} |
88 |
|
Logging.ATSAdminLog.Debug("Created Tables in AnywhereTS Database"); |
89 |
} |
} |
90 |
catch (SqlException sql_ex1) |
catch (SqlException sql_ex1) |
91 |
{ |
{ |
92 |
SqlException sql_ex = (sql_ex1.GetBaseException() as SqlException); |
SqlException sql_ex = (sql_ex1.GetBaseException() as SqlException); |
93 |
MessageBox.Show(string.Format("Failed to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString()); |
MessageBox.Show(string.Format("Failed to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString()); |
94 |
|
|
95 |
|
using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", sql_ex.Number.ToString(), sql_ex.Message, System.Environment.NewLine, sql_ex.ToString()))) |
96 |
|
{ |
97 |
|
Logging.ATSAdminLog.Error("Failed to open connection to AnywhereTS Database"); |
98 |
|
} |
99 |
return bContinue; |
return bContinue; |
100 |
} |
} |
101 |
} |
} |
104 |
Version databaseVersion; // The current version of the database |
Version databaseVersion; // The current version of the database |
105 |
int chkVer = CheckVersion(out databaseVersion); |
int chkVer = CheckVersion(out databaseVersion); |
106 |
VersionCheck verChk = (VersionCheck)chkVer; |
VersionCheck verChk = (VersionCheck)chkVer; |
107 |
MessageBox.Show(string.Format("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString())); |
//MessageBox.Show(string.Format("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString())); |
108 |
|
Logging.ATSAdminLog.DebugFormat("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString()); |
109 |
switch (chkVer) |
switch (chkVer) |
110 |
{ |
{ |
111 |
case (int)VersionCheck.Equal: |
case (int)VersionCheck.Equal: |
125 |
// Run the apropriate upgdrade script(s) |
// Run the apropriate upgdrade script(s) |
126 |
case "1.0.0.0": |
case "1.0.0.0": |
127 |
{ // Current database is version 1.0.0.0, update to 1.0.0.1 |
{ // Current database is version 1.0.0.0, update to 1.0.0.1 |
128 |
|
Logging.ATSAdminLog.DebugFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.0", "1.0.0.1"); |
129 |
bContinue = RunScript(Resource1.UpdateDatabase1.ToString()); |
bContinue = RunScript(Resource1.UpdateDatabase1.ToString()); |
130 |
|
Logging.ATSAdminLog.DebugFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.0", "1.0.0.1"); |
131 |
goto case "1.0.0.1"; // Continue and upgrade one more step |
goto case "1.0.0.1"; // Continue and upgrade one more step |
132 |
} |
} |
133 |
case "1.0.0.1": |
case "1.0.0.1": |
134 |
{ // Current database is version 1.0.0.1, update to 1.0.0.2 |
{ // Current database is version 1.0.0.1, update to 1.0.0.2 |
135 |
|
Logging.ATSAdminLog.DebugFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.1", "1.0.0.2"); |
136 |
bContinue = RunScript(Resource1.UpdateDatabase2.ToString()); |
bContinue = RunScript(Resource1.UpdateDatabase2.ToString()); |
137 |
|
Logging.ATSAdminLog.DebugFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.2"); |
138 |
goto case "1.0.0.2"; // Continue and upgrade one more step |
goto case "1.0.0.2"; // Continue and upgrade one more step |
139 |
} |
} |
140 |
case "1.0.0.2": |
case "1.0.0.2": |
141 |
{ // Current database is version 1.0.0.2, update to 1.0.0.3 |
{ // Current database is version 1.0.0.2, update to 1.0.0.3 |
142 |
|
Logging.ATSAdminLog.DebugFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.3"); |
143 |
bContinue = RunScript(Resource1.UpdateDatabase3.ToString()); |
bContinue = RunScript(Resource1.UpdateDatabase3.ToString()); |
144 |
|
Logging.ATSAdminLog.DebugFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.3"); |
145 |
break; |
break; |
146 |
} |
} |
147 |
|
|
149 |
default: |
default: |
150 |
{ |
{ |
151 |
MessageBox.Show("Error: Not able to upgrade database (51188)"); |
MessageBox.Show("Error: Not able to upgrade database (51188)"); |
152 |
|
Logging.ATSAdminLog.DebugFormat("Failed to upgrade Database from version: {0} to version: {1}", databaseVersion.ToString(), CURRENT_DB_VERSION.ToString()); |
153 |
break; |
break; |
154 |
} |
} |
155 |
} |
} |