当前位置: 首页>>代码示例>>C#>>正文


C# SqlCommand.LexExecuteReader方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlCommand.LexExecuteReader方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.LexExecuteReader方法的具体用法?C# SqlCommand.LexExecuteReader怎么用?C# SqlCommand.LexExecuteReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlCommand的用法示例。


在下文中一共展示了SqlCommand.LexExecuteReader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DropDataBase

        public static object DropDataBase(IDBUpdaterInteractionContext context)
        {
            var dbname = context.DBName;

            context.Connection.Close();
            SqlConnection.ClearAllPools();

            using (var newConnection = GetNewConnectionWithoutDBRefference(context.Connection))
            {
                newConnection.Open();

                using (var c = new SqlCommand(GetDBUsageSql(dbname), newConnection))
                {
                    var ok = true;
                    var sb = new StringBuilder("Database is using by following clients:");
                    sb.AppendLine();
                    using (var r = c.LexExecuteReader())
                    {
                        while (r.Read())
                        {
                            string status = r.GetString(0).Trim();
                            string host = r.GetString(1).Trim();
                            string prg = r.GetString(2).Trim();

                            if ((host.IsNotNull() || prg.IsNotNull()))
                            {
                                ok = false;
                                sb.AppendLine(string.Format("{0} | {1} | {2}", status, host, prg));
                            }
                        }
                    }
                    if (!ok)
                    {
                        sb.AppendLine();
                        sb.Append("Close ALL connection?");
                        if (
                            MessageBox.Show(sb.ToString(), "Close confirmation", MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Exclamation) == DialogResult.Yes)
                        {
                            c.CommandText =
                                string.Format("ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE",
                                              dbname);
                            c.CommandType = CommandType.Text;
                            c.LexExecuteNonQuery();
                        }
                        else
                            return false;
                    }
                }

                using (var c = new SqlCommand(string.Format("DROP DATABASE [{0}]", dbname), newConnection))
                {
                    c.LexExecuteNonQuery();
                }
            }
            return true;
        }
开发者ID:supermuk,项目名称:iudico,代码行数:57,代码来源:DBUpdateManager.cs

示例2: PerformSelectDataBase

        private bool PerformSelectDataBase()
        {
            string serverInstance = tbServerInstance.Text.Trim();
            string dbName = tbDBName.Text.Trim();

            UseWaitCursor = true;
            bool disposeConnetion = true;
            var s = new SqlConnection(new SqlConnectionStringBuilder
            {
                DataSource = serverInstance,
                IntegratedSecurity = true,
            }.ToString());
            var Dbs = new List<string>();
            try
            {
                s.Open();
                var c = new SqlCommand("EXEC sp_databases", s);
                using (var r = c.LexExecuteReader())
                {
                    while (r.Read())
                    {
                        Dbs.Add(r.GetString(0));
                    }
                }

                if (Dbs.IndexOf(dbName) < 0)
                {
                    if (MessageBox.Show(this, string.Format("DataBase '{0}' was not found in {1}. Do you want to create it?", dbName, serverInstance), "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        c.CommandText = @"CREATE DATABASE [" + dbName + "]";
                        c.LexExecuteNonQuery();
                    }
                    else
                    {
                        return false;
                    }
                }

                s.Close();
                s.ConnectionString = new SqlConnectionStringBuilder
                {
                    DataSource = serverInstance,
                    IntegratedSecurity = true,
                    InitialCatalog = dbName
                }.ToString();
                s.Open();

                disposeConnetion = false;
                var f = new frmDBStatus(s, this, dbName);
                f.Show(this);
                return true;
            }
            catch (SqlException se)
            {
                MessageBox.Show(this, se.Message, string.Format("Error on openning '{0}'", serverInstance), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            finally
            {
                UseWaitCursor = false;
                if (disposeConnetion)
                {
                    s.Dispose();
                }
            }
        }
开发者ID:supermuk,项目名称:iudico,代码行数:66,代码来源:frmSelectDB.cs

示例3: IsDBVersionExists

 private static bool IsDBVersionExists(IDBUpdaterInteractionContext f)
 {
     using (var c = new SqlCommand("select * from sys.tables where name = 'sysDBVersion'", f.Connection))
     {
         using (var r = c.LexExecuteReader())
         {
             return r.Read();
         }
     }
 }
开发者ID:supermuk,项目名称:iudico,代码行数:10,代码来源:DBUpdateManager.cs

示例4: GetScriptsToRun

        public static object GetScriptsToRun(IDBUpdaterInteractionContext context)
        {
            var runned = new List<string>();
            var version = 0;
            var files = new List<string>(Directory.GetFiles(context.DBScriptsPath, "*.sql"));
            using (var c = new SqlCommand("select * from sysDBVersion", context.Connection))
            {
                using (var r = c.LexExecuteReader())
                {
                    while (r.Read())
                    {
                        version = Math.Max(r.GetInt32(0), version);
                        runned.Add(r.GetString(1));
                    }
                }
            }

            for (int i = 0; i < files.Count; i++)
            {
                files[i] = Path.GetFileNameWithoutExtension(files[i]);
            }

            foreach (var r in runned)
            {
                var ind = files.FindIndex(sc => sc.EndsWith(r));
                if (ind >= 0)
                {
                    files.RemoveAt(ind);
                }
            }
            return new KeyValuePair<IList<string>, IList<string>>(runned, files);
        }
开发者ID:supermuk,项目名称:iudico,代码行数:32,代码来源:DBUpdateManager.cs


注:本文中的System.Data.SqlClient.SqlCommand.LexExecuteReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。