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


C# SqlCommand.LexExecuteNonQuery方法代码示例

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


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

示例1: 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

示例2: ReCreateDataBase

        public static void ReCreateDataBase(IDBUpdaterUserInteractionContext view)
        {
            try
            {
                var dbname = view.DBName;

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

                using (var newConnection = new SqlConnection(new SqlConnectionStringBuilder
                {
                    DataSource = view.Connection.DataSource,
                    IntegratedSecurity = true
                }.ToString()))
                {
                    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.ExecuteReader())
                        {
                            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;
                        }
                    }

                    using (var c = new SqlCommand(string.Format("DROP DATABASE [{0}]", dbname), newConnection))
                    {
                        c.LexExecuteNonQuery();

                        c.CommandText = string.Format("CREATE DATABASE [{0}]", dbname);
                        c.LexExecuteNonQuery();
                    }
                }

                view.Connection.Open();

                CreateSysDbVersionTable(view);
            }
            finally
            {
                if (view.Connection.State != ConnectionState.Open)
                {
                    view.Connection.Open();
                }
                view.AsyncEnQueueOperation(GetScriptsToRun, "Getting scripts to run...");
            }
        }
开发者ID:supermuk,项目名称:iudico,代码行数:78,代码来源:DBUpdateManager.cs

示例3: CreateSysDbVersionTable

        private static void CreateSysDbVersionTable(IDBUpdaterUserInteractionContext f)
        {
            using (var c = new SqlCommand(CreateSysDbVersionTableScript, f.Connection))
            {
                c.LexExecuteNonQuery();

                c.CommandText = CreateSysDbVersionTriggerScript;
                c.LexExecuteNonQuery();

                c.CommandText = GetDBVersionProcSql(0, false);
                c.LexExecuteNonQuery();

                c.CommandText = CreateUpgradeDBProcedure;
                c.LexExecuteNonQuery();
            }
        }
开发者ID:supermuk,项目名称:iudico,代码行数:16,代码来源:DBUpdateManager.cs

示例4: UpgrateToNextVersion

        public static Action<IDBUpdaterUserInteractionContext> UpgrateToNextVersion(int dbVersion, string sqlscript, string scriptFileName)
        {
            return frmDBStatus =>
            {
                using (var transaction = frmDBStatus.Connection.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    using (var cmd = new SqlCommand("select dbo.GetDBVersion()", transaction.Connection)
                    {
                        Transaction = transaction
                    })
                    {
                        try
                        {
                            var v = cmd.LexExecuteScalar<int>();
                            if (v != dbVersion)
                            {
                                throw new InvalidDBVersionException(v);
                            }

                            foreach (var cmdText in SplitSqlCommands(sqlscript))
                            {
                                cmd.CommandText = cmdText;
                                cmd.LexExecuteNonQuery();
                            }

                            cmd.CommandText = GetDBVersionProcSql(dbVersion + 1, true);
                            cmd.ExecuteScalar();

                            cmd.CommandText = "INSERT INTO sysDBVersion (VersionNumber, ScriptFileName, Date) VALUES (@version, @filename, @date)";
                            cmd.Parameters.Assign(new
                            {
                                version = dbVersion,
                                filename = scriptFileName,
                                date = DateTime.Now
                            });
                            cmd.LexExecuteNonQuery();

                            transaction.Commit();
                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
            };
        }
开发者ID:supermuk,项目名称:iudico,代码行数:48,代码来源:DBUpdateManager.cs

示例5: 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

示例6: CreateDataBase

        public static object CreateDataBase(IDBUpdaterInteractionContext context)
        {
            var dbname = context.DBName;
            using (var newConnection = GetNewConnectionWithoutDBRefference(context.Connection))
            {
                context.Connection.Close();

                newConnection.Open();
                using (var c = new SqlCommand(string.Format("CREATE DATABASE [{0}]", dbname), newConnection))
                {
                    c.LexExecuteNonQuery();
                }
            }

            context.Connection.ConnectionString = new SqlConnectionStringBuilder(context.Connection.ConnectionString) { InitialCatalog = dbname }.ToString();

            context.Connection.Open();

            CreateSysDbVersionTable(context);
            return true;
        }
开发者ID:supermuk,项目名称:iudico,代码行数:21,代码来源:DBUpdateManager.cs


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