22 |
|
|
23 |
const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser"; |
const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser"; |
24 |
|
|
25 |
public static string InstanceName = Properties.Settings.Default.atsConnectionString.Substring(Properties.Settings.Default.atsConnectionString.IndexOf(@"\"), Properties.Settings.Default.atsConnectionString.IndexOf(@";Database")).Replace(@"\", "").Replace(@";", "").Replace(@"Database", ""); |
public static string InstanceName |
26 |
|
{ |
27 |
|
get |
28 |
|
{ |
29 |
|
bool start = false; |
30 |
|
bool end = false; |
31 |
|
List<char> pChars = new List<char>(); |
32 |
|
foreach (char c in Properties.Settings.Default.atsConnectionString.ToCharArray()) |
33 |
|
{ |
34 |
|
if (c == '\\') { start = true; continue; } |
35 |
|
if (c == ';') { end = true; } |
36 |
|
if (end) break; |
37 |
|
if (start) { pChars.Add(c); } |
38 |
|
} |
39 |
|
return new string(pChars.ToArray()); |
40 |
|
} |
41 |
|
} |
42 |
public bool SetupDatabase() |
public bool SetupDatabase() |
43 |
{ |
{ |
44 |
bool bContinue = false; |
bool bContinue = false; |
|
bool bCreateDB = false; |
|
45 |
// Create a connection to SQL Server |
// Create a connection to SQL Server |
46 |
try |
try |
47 |
{ |
{ |
48 |
sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString; |
sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString; |
49 |
sqlCon.Open(); |
sqlCon.Open(); |
50 |
} |
} |
51 |
catch (SqlException sql_ex) |
catch |
52 |
{ |
{ |
53 |
//MessageBox.Show(string.Format("Fail to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString()); |
//MessageBox.Show(string.Format("Fail to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString()); |
54 |
//return bContinue; |
//return bContinue; |
55 |
//bCreateDB = true; |
//bCreateDB = true; |
56 |
try |
try |
57 |
{ |
{ |
58 |
sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS","master"); |
sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"); |
59 |
sqlCon.Open(); |
sqlCon.Open(); |
60 |
RunScript(Resource1.CreateDatabase.ToString()); |
RunScript(Resource1.CreateDatabase.ToString()); |
61 |
sqlCon.Close(); |
sqlCon.Close(); |
62 |
sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString; |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString); |
63 |
sqlCon.Open(); |
sqlCon.Open(); |
64 |
} |
} |
65 |
catch (SqlException sql_ex1) |
catch (SqlException sql_ex1) |
66 |
{ |
{ |
67 |
MessageBox.Show(string.Format("Fail to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex1.Number.ToString() + " " + sql_ex1.Message.ToString()); |
SqlException sql_ex = (sql_ex1.GetBaseException() as SqlException); |
68 |
|
MessageBox.Show(string.Format("Failed to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString()); |
69 |
return bContinue; |
return bContinue; |
70 |
} |
} |
71 |
} |
} |
72 |
|
|
73 |
// Now that you are connected to Express, check the database versions |
// Now that you are connected to Express, check the database versions |
|
|
|
74 |
Version databaseVersion; // The current version of the database |
Version databaseVersion; // The current version of the database |
|
|
|
75 |
int chkVer = CheckVersion(out databaseVersion); |
int chkVer = CheckVersion(out databaseVersion); |
76 |
VersionCheck verChk = (VersionCheck)chkVer; |
VersionCheck verChk = (VersionCheck)chkVer; |
77 |
//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())); |
|
|
|
78 |
switch (chkVer) |
switch (chkVer) |
79 |
{ |
{ |
80 |
case (int)VersionCheck.Equal: |
case (int)VersionCheck.Equal: |