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); |
static Version CURRENT_DB_VERSION = new Version(1, 0, 0, 3); |
31 |
public static string InstanceName |
public static string InstanceName |
32 |
{ |
{ |
33 |
get |
get |
226 |
string strResult; |
string strResult; |
227 |
|
|
228 |
//Verify that the AnywhereTS database exists |
//Verify that the AnywhereTS database exists |
|
sqlCmd = new SqlCommand("select count(*) from master..sysdatabases where name='AnywhereTS'", sqlCon); |
|
|
strResult = sqlCmd.ExecuteScalar().ToString(); |
|
229 |
|
|
230 |
if (strResult == "0") |
using (log4net.NDC.Push(string.Format("SQL STATMENT={0}", "select count(*) from master..sysdatabases where name='AnywhereTS'"))) |
|
{ |
|
|
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
|
|
sqlCon.Open(); |
|
|
RunScript(Resource1.CreateDatabase.ToString()); |
|
|
sqlCon.Close(); |
|
|
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
|
|
sqlCon.Open(); |
|
|
RunScript(Resource1.CreateTables.ToString()); |
|
|
sqlCon.Close(); |
|
|
} |
|
|
try |
|
231 |
{ |
{ |
232 |
sqlCon.Close(); |
Logging.ATSAdminLog.Debug("Getting Coount of AnywhereTS databases"); |
233 |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString); |
sqlCmd = new SqlCommand("select count(*) from master..sysdatabases where name='AnywhereTS'", sqlCon); |
234 |
sqlCon.Open(); |
strResult = sqlCmd.ExecuteScalar().ToString(); |
|
sqlCmd = new SqlCommand("SELECT value from AnywhereTS..AppInfo where property='version'", sqlCon); |
|
|
strResult = (string)sqlCmd.ExecuteScalar(); |
|
|
sqlCon.Close(); |
|
235 |
} |
} |
236 |
catch |
Logging.ATSAdminLog.DebugFormat("AnywhereTS databases Count={0}", strResult); |
237 |
|
|
238 |
|
if (strResult == "0") |
239 |
{ |
{ |
240 |
// the database exists, but one or more tables are missing |
|
241 |
try |
|
242 |
|
using (log4net.NDC.Push(string.Format("SQL Statment={0}", Resource1.CreateDatabase.ToString()))) |
243 |
{ |
{ |
244 |
|
Logging.ATSAdminLog.Debug("Creating Database AnywhereTS in CheckVersion()"); |
245 |
|
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
246 |
|
sqlCon.Open(); |
247 |
|
RunScript(Resource1.CreateDatabase.ToString()); |
248 |
|
sqlCon.Close(); |
249 |
|
} |
250 |
|
Logging.ATSAdminLog.Debug("Created Database AnywhereTS in CheckVersion()"); |
251 |
|
|
252 |
|
using (log4net.NDC.Push(string.Format("SQL Statment={0}", Resource1.CreateTables.ToString()))) |
253 |
|
{ |
254 |
|
Logging.ATSAdminLog.Debug("Creating Tables in AnywhereTS Database in CheckVersion()"); |
255 |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
256 |
sqlCon.Open(); |
sqlCon.Open(); |
257 |
RunScript(Resource1.CreateTables.ToString()); |
RunScript(Resource1.CreateTables.ToString()); |
258 |
sqlCon.Close(); |
sqlCon.Close(); |
259 |
|
} |
260 |
|
Logging.ATSAdminLog.Debug("Created Tables in AnywhereTS Database in CheckVersion()"); |
261 |
|
} |
262 |
|
try |
263 |
|
{ |
264 |
|
using (log4net.NDC.Push(string.Format("SQL Statment={0}", "SELECT value from AnywhereTS..AppInfo where property='version'"))) |
265 |
|
{ |
266 |
|
Logging.ATSAdminLog.Debug("Gettting AnywhereTS Database Version"); |
267 |
|
sqlCon.Close(); |
268 |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString); |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString); |
269 |
sqlCon.Open(); |
sqlCon.Open(); |
270 |
sqlCmd = new SqlCommand("SELECT value from AnywhereTS..AppInfo where property='version'", sqlCon); |
sqlCmd = new SqlCommand("SELECT value from AnywhereTS..AppInfo where property='version'", sqlCon); |
271 |
strResult = (string)sqlCmd.ExecuteScalar(); |
strResult = (string)sqlCmd.ExecuteScalar(); |
272 |
|
sqlCon.Close(); |
273 |
|
} |
274 |
|
Logging.ATSAdminLog.DebugFormat("AnywhereTS database version={0}", strResult); |
275 |
|
} |
276 |
|
catch(SqlException ex) |
277 |
|
{ |
278 |
|
// the database exists, but one or more tables are missing |
279 |
|
using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", ex.Number.ToString(), ex.Message, System.Environment.NewLine, ex.ToString()))) |
280 |
|
{ |
281 |
|
Logging.ATSAdminLog.Error("Failed to get database version"); |
282 |
} |
} |
283 |
catch |
try |
284 |
{ |
{ |
285 |
|
|
286 |
|
using (log4net.NDC.Push(string.Format("SQL Statment={0}", Resource1.CreateTables.ToString()))) |
287 |
|
{ |
288 |
|
Logging.ATSAdminLog.Debug("Creating Tables in AnywhereTS Database in CheckVersion()"); |
289 |
|
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
290 |
|
sqlCon.Open(); |
291 |
|
RunScript(Resource1.CreateTables.ToString()); |
292 |
|
sqlCon.Close(); |
293 |
|
} |
294 |
|
Logging.ATSAdminLog.Debug("Created Tables in AnywhereTS Database in CheckVersion()"); |
295 |
|
|
296 |
|
using (log4net.NDC.Push(string.Format("SQL Statment={0}", "SELECT value from AnywhereTS..AppInfo where property='version'"))) |
297 |
|
{ |
298 |
|
Logging.ATSAdminLog.Debug("Gettting AnywhereTS Database Version"); |
299 |
|
sqlCon.Close(); |
300 |
|
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString); |
301 |
|
sqlCon.Open(); |
302 |
|
sqlCmd = new SqlCommand("SELECT value from AnywhereTS..AppInfo where property='version'", sqlCon); |
303 |
|
strResult = (string)sqlCmd.ExecuteScalar(); |
304 |
|
sqlCon.Close(); |
305 |
|
} |
306 |
|
Logging.ATSAdminLog.DebugFormat("AnywhereTS database version={0}", strResult); |
307 |
|
} |
308 |
|
catch(SqlException ex1) |
309 |
|
{ |
310 |
|
using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", ex1.Number.ToString(), ex1.Message, System.Environment.NewLine, ex1.ToString()))) |
311 |
|
{ |
312 |
|
Logging.ATSAdminLog.Error("Failed to get database version"); |
313 |
|
} |
314 |
return (int)VersionCheck.Failed; |
return (int)VersionCheck.Failed; |
315 |
} |
} |
316 |
} |
} |
331 |
catch (SqlException sql_ex) |
catch (SqlException sql_ex) |
332 |
{ |
{ |
333 |
MessageBox.Show(sql_ex.Number.ToString() + " " + sql_ex.Message.ToString()); |
MessageBox.Show(sql_ex.Number.ToString() + " " + sql_ex.Message.ToString()); |
334 |
|
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()))) |
335 |
|
{ |
336 |
|
Logging.ATSAdminLog.Error("Failed to check database version"); |
337 |
|
} |
338 |
return (int)VersionCheck.Failed; |
return (int)VersionCheck.Failed; |
339 |
} |
} |
340 |
catch (Exception system_ex) |
catch (Exception system_ex) |
341 |
{ |
{ |
342 |
MessageBox.Show(system_ex.Message.ToString()); |
MessageBox.Show(system_ex.Message.ToString()); |
343 |
|
using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", system_ex.Message, System.Environment.NewLine, system_ex.ToString()))) |
344 |
|
{ |
345 |
|
Logging.ATSAdminLog.Error("Failed to check database version"); |
346 |
|
} |
347 |
return (int)VersionCheck.Failed; |
return (int)VersionCheck.Failed; |
348 |
} |
} |
349 |
} |
} |