/[AnywhereTS-MSSQL]/trunk/TSAdminTool/Database.cs
ViewVC logotype

Diff of /trunk/TSAdminTool/Database.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/TSAdminTool/Database.cs	2012/07/13 22:37:40	87
+++ trunk/TSAdminTool/Database.cs	2012/07/13 22:42:09	88
@@ -33,17 +33,18 @@
         {
             get
             {
-                bool start = false;
-                bool end = false;
-                List<char> pChars = new List<char>();
-                foreach (char c in Properties.Settings.Default.atsConnectionString.ToCharArray())
-                {
-                    if (c == '\\') { start = true; continue; }
-                    if (c == ';') { end = true; }
-                    if (end) break;
-                    if (start) { pChars.Add(c); }
-                }
-                return new string(pChars.ToArray());
+                //bool start = false;
+                //bool end = false;
+                //List<char> pChars = new List<char>();
+                //foreach (char c in Properties.Settings.Default.atsConnectionString.ToCharArray())
+                //{
+                //    if (c == '\\') { start = true; continue; }
+                //    if (c == ';') { end = true; }
+                //    if (end) break;
+                //    if (start) { pChars.Add(c); }
+                //}
+                //return new string(pChars.ToArray());
+                return Properties.Settings.Default.DBInstance;
             }
         }
         public bool SetupDatabase()
@@ -272,28 +273,49 @@
                 }
                 else if (db_count == 0)
                 {
-
-                    #region database does not exist
-                    //using (log4net.NDC.Push(string.Format("SQL Statment={0}", SQLServerResources.CreateDatabase)))
-                    //{
-                    Logging.ATSAdminLog.Debug(string.Format("Creating Database {0} in CheckVersion()", ATSGlobals.strDatabaseName));
-                    sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace(ATSGlobals.strDatabaseName, "master"));
-                    if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
-                    RunScript(SQLServerResources.CreateDatabase);
-                    //RunScript(CreateDatabaseUserScript());
-                    sqlCon.Close();
-                    //}
-                    Logging.ATSAdminLog.Debug(string.Format("Created Database {0} in CheckVersion()", ATSGlobals.strDatabaseName));
-
-                    //using (log4net.NDC.Push(string.Format("SQL Statment={0}", SQLServerResources.CreateTables)))
-                    //{
-                    Logging.ATSAdminLog.Debug(string.Format("Creating Tables in {0} Database in CheckVersion()", ATSGlobals.strDatabaseName));
-                    sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace(ATSGlobals.strDatabaseName, "master"));
-                    if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
-                    RunScript(SQLServerResources.CreateTables);
-                    sqlCon.Close();
-                    //}
-                    Logging.ATSAdminLog.Debug(string.Format("Created Tables in {0} Database in CheckVersion()", ATSGlobals.strDatabaseName));
+                    #region Database Creation support
+                    using (MsSqlConnector conn = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, ATSGlobals.strDatabaseName))
+                    {
+                        try
+                        {
+                            conn.CreateConnection(out ErrorInfo);
+                            conn.OpenConnection(out ErrorInfo);
+                        }
+                        catch (Exception ex)
+                        {
+                            try
+                            {
+                                conn.Dispose();
+                                using (MsSqlConnector conn1 = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, "master"))
+                                {
+                                    try
+                                    {
+                                        conn1.CreateConnection(out ErrorInfo);
+                                        conn1.OpenConnection(out ErrorInfo);
+
+                                        // create datagbase
+                                        Logging.ATSAdminLog.Info(string.Format("Creating Database {0}", ATSGlobals.strDatabaseName));
+                                        RunScript(SQLServerResources.CreateDatabase, conn1, out ErrorInfo);
+                                        Logging.ATSAdminLog.Info(string.Format("Created Database {0}", ATSGlobals.strDatabaseName));
+
+                                        // create tables
+                                        Logging.ATSAdminLog.Info(string.Format("Creating Tables in {0} Database", ATSGlobals.strDatabaseName));
+                                        RunScript(SQLServerResources.CreateTables, conn1, out ErrorInfo);
+                                        Logging.ATSAdminLog.Info(string.Format("Created Tables in {0} Database", ATSGlobals.strDatabaseName));
+                                    }
+                                    catch (Exception ex1)
+                                    {
+                                        if (ErrorInfo == null) { ErrorInfo = new Exception(ex1.Message, ex); }
+                                    }
+                                }
+                            }
+                            catch (Exception ex1)
+                            {
+                                if (ErrorInfo == null) { ErrorInfo = new Exception(ex1.Message, ex); }
+                            }
+                        }
+                    }
+                    if (ErrorInfo != null) { return false; }
                     #endregion
                 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22