Пример #1
0
        public static List <string> GetSqlServers()
        {
            List <SqlServerRef> all = SqlDiscovery.GetLocalDbAndServerList();
            int prevWorkers, prevPorts;

            ThreadPool.GetMinThreads(out prevWorkers, out prevPorts);
            var workers = Math.Max(prevWorkers, all.Count + 2);

            ThreadPool.SetMinThreads(workers, prevPorts);

            return(all.Select(x => x.ConnectionString)
                   .AsParallel().WithDegreeOfParallelism(Math.Max(all.Count, 2))
                   .Where(IsAlive)
                   .ToList());
        }
        public void Local_Instances_Contains_Data()
        {
            // LocalInstancesDiscovery.Get() - does not return LocalDB instances, nut includes version using exe file version
            // LocalInstanceInfo servers = LocalInstancesDiscovery.Get();
            List <SqlServerRef> servers = SqlDiscovery.GetLocalDbAndServerList();

            // StringBuilder dump = new StringBuilder();
            // var stringWriter = new StringWriter(dump);
            // servers.WriteToXml(stringWriter);
            Console.WriteLine("FOUND SQL Instances:" + string.Join(",", servers.Select(x => x.Data)));

            Assert.IsTrue(servers.Count > 0, "SQL Server is required. Either running or stopped");
            foreach (var i in servers)
            {
                // TODO: Assert.IsNotNull(i.Version, "File version property of instance {0} is required", i);
                // TODO: Assert.IsTrue(i.Version.Major != 0, "Major file version of instance {0} should be not zero", i);
                Assert.IsNotNull(i.DataSource, "Instance should have name");
            }
        }
        public void Local_Instances_GetFull()
        {
            List <SqlServerRef> servers = SqlDiscovery.GetLocalDbAndServerList();

            Parallel.ForEach(servers, sqlRef =>
            {
                string ver = null;
                SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(sqlRef.ConnectionString);
                try
                {
                    using (SqlConnection con = new SqlConnection(sqlRef.ConnectionString))
                    {
                        ver = con.Manage().ShortServerVersion.ToString();
                    }
                }
                catch (Exception ex)
                {
                    ver = ex.GetType().Name;
                }

                Console.WriteLine($"{b.DataSource} --> {ver}");
                List <SqlServerRef> transportList = sqlRef.ProbeTransports(9000);
            });
        }
 public void Local_Instances_Get()
 {
     List <SqlServerRef> servers = SqlDiscovery.GetLocalDbAndServerList();
 }