예제 #1
0
        public void RefreshLoad()
        {
            ObservableCollection <string> Serverlist = new ObservableCollection <string>();
            SqlDataSourceEnumerator       instance   = SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = instance.GetDataSources();
            foreach (System.Data.DataRow row in table.Rows)
            {
                if (row["ServerName"] != DBNull.Value && Environment.MachineName.Equals(row["ServerName"].ToString()))
                {
                    string item = string.Empty;
                    item = row["ServerName"].ToString();
                    if (row["InstanceName"] != DBNull.Value || !string.IsNullOrEmpty(Convert.ToString(row["InstanceName"]).Trim()))
                    {
                        item += @"\" + Convert.ToString(row["InstanceName"]).Trim();
                    }
                    Serverlist.Add(item);
                }
            }
            SelectServerName = Serverlist;
            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle                    = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName                       = "cmd.exe";
            startInfo.Arguments                      = "/C sqllocaldb i";
            process.StartInfo                        = startInfo;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.CreateNoWindow         = true;
            process.Start();
            var    result          = process.StandardOutput.ReadLine();
            string LocalServerName = string.Concat(@"(LocalDb)\", result);

            SelectServerName.Add(LocalServerName);
        }
        private void SelectDatabase()
        {
            ObservableCollection <string> list       = new ObservableCollection <string>();
            ObservableCollection <string> Storedlist = new ObservableCollection <string>();
            // var connectionString = ConfigurationManager.ConnectionStrings["SASEntitiesEDM"].ConnectionString;
            // string connectionstring = "data source=108.168.203.227,7008;user id=SimpleAccounting;password=SimpleAccounting;";
            //string connectionstring = "data source=(LocalDb)\\MSSQLLocalDB;Trusted_Connection=True;Integrated Security=True;";

            ObservableCollection <string> Serverlist = new ObservableCollection <string>();
            SqlDataSourceEnumerator       instance   = SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = instance.GetDataSources();
            foreach (System.Data.DataRow row in table.Rows)
            {
                if (row["ServerName"] != DBNull.Value && Environment.MachineName.Equals(row["ServerName"].ToString()))
                {
                    string item = string.Empty;
                    item = row["ServerName"].ToString();
                    if (row["InstanceName"] != DBNull.Value || !string.IsNullOrEmpty(Convert.ToString(row["InstanceName"]).Trim()))
                    {
                        item += @"\" + Convert.ToString(row["InstanceName"]).Trim();
                    }
                    Serverlist.Add(item);
                }
            }
            SelectServerName = Serverlist;
            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle                    = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName                       = "cmd.exe";
            startInfo.Arguments                      = "/C sqllocaldb i";
            process.StartInfo                        = startInfo;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.CreateNoWindow         = true;
            process.Start();
            var    result          = process.StandardOutput.ReadLine();
            string LocalServerName = string.Concat(@"(LocalDb)\", result);

            SelectServerName.Add(LocalServerName);
        }