• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# MySqlClient.MySqlScript类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MySql.Data.MySqlClient.MySqlScript的典型用法代码示例。如果您正苦于以下问题:C# MySqlScript类的具体用法?C# MySqlScript怎么用?C# MySqlScript使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MySqlScript类属于MySql.Data.MySqlClient命名空间,在下文中一共展示了MySqlScript类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Setup

        public override void Setup()
        {
            base.Setup();

              // Replace existing listeners with listener for testing.
              Trace.Listeners.Clear();
              Trace.Listeners.Add(this.asertFailListener);

              ResourceManager r = new ResourceManager("MySql.Data.Entity.Tests.Properties.Resources", typeof(BaseEdmTest).Assembly);
              string schema = r.GetString("schema");
              MySqlScript script = new MySqlScript(conn);
              script.Query = schema;
              script.Execute();

              // now create our procs
              schema = r.GetString("procs");
              script = new MySqlScript(conn);
              script.Delimiter = "$$";
              script.Query = schema;
              script.Execute();

              //ModelFirstModel1
              schema = r.GetString("ModelFirstModel1");
              script = new MySqlScript(conn);
              script.Query = schema;
              script.Execute();

              MySqlCommand cmd = new MySqlCommand("DROP DATABASE IF EXISTS `modeldb`", rootConn);
              cmd.ExecuteNonQuery();
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:30,代码来源:BaseEdmTest.cs


示例2: CanCreateDBScriptWithDateTimePrecision

        public void CanCreateDBScriptWithDateTimePrecision()
        {
            if (Version < new Version(5, 6, 5)) return;

             MySqlConnection c = new MySqlConnection(conn.ConnectionString);
             c.Open();

             var script = new MySqlScript(c);
             using (var ctx = new datesTypesEntities())
             {
               MySqlCommand query = new MySqlCommand("Create database test_types", c);
               query.Connection = c;
               query.ExecuteNonQuery();
               c.ChangeDatabase("test_types");

               script.Query = ctx.CreateDatabaseScript();
               script.Execute();

               query = new MySqlCommand("Select Column_name, Is_Nullable, Data_Type, DateTime_Precision from information_schema.Columns where table_schema ='" + c.Database + "' and table_name = 'Products' and column_name ='DateTimeWithPrecision'", c);
               query.Connection = c;
               MySqlDataReader reader = query.ExecuteReader();
               while (reader.Read())
               {
              Assert.AreEqual("DateTimeWithPrecision", reader[0].ToString());
              Assert.AreEqual("NO", reader[1].ToString());
              Assert.AreEqual("datetime", reader[2].ToString());
              Assert.AreEqual("3", reader[3].ToString());
               }
               reader.Close();
               ctx.DeleteDatabase();
               c.Close();
             }
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:33,代码来源:DatesTypesTests.cs


示例3: Button4_Click

 private void Button4_Click(object sender, EventArgs e)
 {
     if (
         MessageBox.Show(this,
             @"การสร้างฐานข้อมูลใหม่จะลบ ฐานข้อมูลเก่าออกทั้งหมด คุณต้องการจะดำเนินการต่อหรือไม่?",
             @"ลบฐานข้อมูล", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         try
         {
             if (_conn.State != ConnectionState.Closed)
             {
                 _conn.Close();
             }
             _conn.Open();
             var sc = new MySqlScript(_conn, Settings.Default.sql);
             if (sc.Execute() >= 1)
             {
                 MessageBox.Show(@"สร้างฐานข้อมูลสำเร็จ");
             }
             else
             {
                 MessageBox.Show(@"สร้างฐานข้อมูลล้มเหลว");
             }
         }
         catch (MySqlException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
开发者ID:epiczeth,项目名称:ATGraphicHouse,代码行数:30,代码来源:frmMain.cs


示例4: LoadSchema

        protected void LoadSchema(int version)
        {
            if (version < 1) return;

              MySQLMembershipProvider provider = new MySQLMembershipProvider();

              ResourceManager r = new ResourceManager("MySql.Web.Properties.Resources", typeof(MySQLMembershipProvider).Assembly);
              string schema = r.GetString(String.Format("schema{0}", version));
              MySqlScript script = new MySqlScript(conn);
              script.Query = schema;

              try
              {
            script.Execute();
              }
              catch (MySqlException ex)
              {
            if (ex.Number == 1050 && version == 7)
            {
              // Schema7 performs several renames of tables to their lowercase representation.
              // If the current server OS does not support renaming to lowercase, then let's just continue.
              script.Query = "UPDATE my_aspnet_schemaversion SET version=7";
              script.Execute();
            }
              }
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:26,代码来源:BaseTest.cs


示例5: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("此操作会清空软件中的所有数据,如果有数据,请做好数据备份(导出)!您是否继续?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    using (MySqlConnection conn = DBA.MySqlDbAccess.GetMySqlConnection())
                    {

                        conn.Open();

                        string sql = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "xy.dll", Encoding.GetEncoding("utf-8"));
                        MySqlScript script = new MySqlScript(conn);

                        script.Query = sql;
                        int count = script.Execute();
                    }
                    MessageBox.Show("数据库已更新至最新版本!", "提示");
                    log.Info("执行数据库重置:" + DateTime.Now.ToString());
                    showversion();
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
            }
        }
开发者ID:xy19xiaoyu,项目名称:PatSI,代码行数:27,代码来源:Version.cs


示例6: run_sql

		// http://bugs.mysql.com/bug.php?id=46429
		public override void run_sql(string sql_to_run)
		{
			if (string.IsNullOrEmpty(sql_to_run)) return;

			// TODO Investigate how pass CommandTimeout into commands which will be during MySqlScript execution.
			var connection = server_connection.underlying_type().downcast_to<MySqlConnection>();
			var script = new MySqlScript(connection, sql_to_run);
			script.Execute();
		}
开发者ID:diyan,项目名称:Roundhouse.MySQL,代码行数:10,代码来源:MySqlDatabase.cs


示例7: RecreateMysqlDatabase

 public static void RecreateMysqlDatabase()
 {
     if (!Connection.State.ToString().Equals("Open"))
     {
         Connection.Open();
     }
     var runScript = new MySqlScript(Connection, Properties.Settings.Default.WipeDatabase);
     runScript.Execute();
     Connection.Close();
 }
开发者ID:jpfrost,项目名称:CotsSalesAndInventory,代码行数:10,代码来源:DatabaseConnection.cs


示例8: ExecuteScript

        public override int ExecuteScript(DbConnection conn, string sql, string delimiter)
        {
            MySqlScript script = new MySqlScript((MySqlConnection) conn, sql);

            if (!string.IsNullOrEmpty(delimiter))
            {
                script.Delimiter = delimiter;
            }

            return script.Execute();
        }
开发者ID:ReinhardHsu,项目名称:devfw,代码行数:11,代码来源:MySqlFactory.cs


示例9: CreateDb

        private bool  CreateDb()
        {
            bool bRs = false;

            string connStr = string.Format("server={0};user={1};database=;password={2};charset=utf8;Allow User Variables=True", txbDbName.Text.Trim(), txbUs.Text.Trim(), txbPw.Text.Trim());
            MySqlConnection conn = new MySqlConnection(connStr);

            try
            {
                Console.WriteLine("Connecting to MySQL...");
                conn.Open();

                string sql = File.ReadAllText("createDb.sql");
                MySqlScript script = new MySqlScript(conn);

                script.Query = sql;
                //script.Delimiter = "??";
                int count = script.Execute();
                
                Console.WriteLine("Executed " + count + " statement(s)");
                //script.Delimiter = ";";
                conn.Close();
                Console.WriteLine("Delimiter: " + script.Delimiter);
                Console.WriteLine("Query: " + script.Query);


                /////////////
                connStr = string.Format("server={0};user={1};database=ztst;password={2};charset=utf8;Allow User Variables=True", txbDbName.Text.Trim(), txbUs.Text.Trim(), txbPw.Text.Trim());
                conn = new MySqlConnection(connStr);
                Console.WriteLine("Connecting to MySQL...");
                conn.Open();

                sql = File.ReadAllText("ztst.sql");
                script = new MySqlScript(conn);
                script.Query = sql;
                //script.Delimiter = "??";
                count = script.Execute();
                Console.WriteLine("Executed " + count + " statement(s)");
                //script.Delimiter = ";";
                conn.Close();
            }
            catch (Exception ex)
            {
                bRs = false;
                Console.WriteLine(ex.ToString());
            }

            //conn.Close();
            Console.WriteLine("Done.");
            return bRs;
        }
开发者ID:xy19xiaoyu,项目名称:PatSI,代码行数:51,代码来源:frmDbConfig.cs


示例10: CheckAndUpData

        public static bool CheckAndUpData()
        {
            DataTable dt = DBA.MySqlDbAccess.GetDataTable(CommandType.Text, "select * from cfg_dbversion");
            string[] files = Directory.GetFiles(System.AppDomain.CurrentDomain.BaseDirectory + "MySqlScript");
            List<int> versionhis = new List<int>();
            foreach (var file in files)
            {
                try
                {
                    versionhis.Add(Convert.ToInt32(Path.GetFileNameWithoutExtension(file)));
                }
                catch (Exception)
                {
                    continue;
                }
            }
            int newserion = versionhis.Max();
            int exeversion = Convert.ToInt32(dt.Rows[0]["dbversion"].ToString());
            string updatatime = dt.Rows[0]["updatetime"].ToString();
            if (newserion == exeversion)
            {
                return true;
            }
            else
            {
                using (MySqlConnection conn = DBA.MySqlDbAccess.GetMySqlConnection())
                {
                    conn.Open();
                    for (int i = exeversion + 1; i <= newserion; i++)
                    {
                        string sql = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "MySqlScript\\" + i, Encoding.GetEncoding("utf-8"));
                        MySqlScript script = new MySqlScript(conn);
                        script.Query = sql;
                        int count = script.Execute();
                        DBA.MySqlDbAccess.ExecNoQuery(CommandType.Text, string.Format("update cfg_dbversion set dbversion={0},updatetime='{1}'", i, DateTime.Now));

                        //try
                        //{
                        //}
                        //catch (Exception ex)
                        //{
                        //    throw ex;
                        //}

                    }
                }
                return true;
            }
        }
开发者ID:xy19xiaoyu,项目名称:PatSI,代码行数:49,代码来源:DBSchemaAutoUpdata.cs


示例11: ExecuteScript

 private void ExecuteScript(string fileName)
 {
     MySqlConnection connection = (MySqlConnection)DbConnectionFactory.CreateAndOpenConnection();
     try
     {
         string fullPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Resources\" + fileName + ".sql";
         MySqlScript script = new MySqlScript(connection, File.ReadAllText(fullPath));
         script.Delimiter = ";";
         script.Execute();
     }
     finally
     {
         DbConnectionFactory.CloseDisposeConnection(connection);
     }
 }
开发者ID:FH-Thomas-Herzog,项目名称:SemesterProject1516,代码行数:15,代码来源:CleanupDatabase.cs


示例12: SetUp

    public SetUp()
    {
      Initialize();
      LoadBaseConfiguration();

      using (MySqlConnection connection = new MySqlConnection(ConnectionStringRootMaster))
      {
        connection.Open();
        MySqlScript script = new MySqlScript(connection);

        // Sets users
        script.Query = Properties.Resources._01_Startup_root_script;
        script.Execute();

        // Sets database objects
        script.Query = string.Format(Properties.Resources._02_Startup_script, databaseName);
        script.Execute();
      }
    }
开发者ID:luguandao,项目名称:MySql.Data,代码行数:19,代码来源:SetUp.cs


示例13: ExecuteScript

        protected override void ExecuteScript(DbConnection conn, string[] script)
        {
            if (!(conn is MySqlConnection))
            {
                base.ExecuteScript(conn, script);
                return;
            }

            MySqlScript scr = new MySqlScript((MySqlConnection) conn);
            {
                foreach (string sql in script)
                {
                    scr.Query = sql;
                    string sql1 = sql;
                    scr.Error += delegate { throw new Exception(sql1); };
                    scr.Execute();
                }
            }
        }
开发者ID:JAllard,项目名称:Aurora-Sim,代码行数:19,代码来源:MySQLMigrations.cs


示例14: UpgradeToCurrent

        private static void UpgradeToCurrent(string connectionString, int version)
        {
            ResourceManager r = new ResourceManager("MySql.Web.Properties.Resources", 
                typeof(SchemaManager).Assembly);

            if (version == Version) return;

            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                connection.Open();

                for (int ver = version + 1; ver <= Version; ver++)
                {
                    string schema = r.GetString(String.Format("schema{0}", ver));
                    MySqlScript script = new MySqlScript(connection);
                    script.Query = schema;
                    script.Execute();
                }
            }
        }
开发者ID:tdhieu,项目名称:openvss,代码行数:20,代码来源:SchemaManager.cs


示例15: Setup

        public override void Setup()
        {
            base.Setup();

            ResourceManager r = new ResourceManager("MySql.Data.Entity.Tests.Properties.Resources", typeof(BaseEdmTest).Assembly);
            string schema = r.GetString("schema");
            MySqlScript script = new MySqlScript(conn);
            script.Query = schema;
            script.Execute();

            // now create our procs
            schema = r.GetString("procs");
            script = new MySqlScript(conn);
            script.Delimiter = "$$";
            script.Query = schema;
            script.Execute();

            MySqlCommand cmd = new MySqlCommand("DROP DATABASE IF EXISTS `modeldb`", rootConn);
            cmd.ExecuteNonQuery();
        }
开发者ID:elevate,项目名称:mysqlconnector-.net,代码行数:20,代码来源:BaseEdmTest.cs


示例16: ExecuteScripts

        public void ExecuteScripts()
        {
            if (string.IsNullOrEmpty(ConnectionString))
                throw new ArgumentNullException("Connection string shouldn´t be null.");

            if (ScriptsFiles == null)
                throw new ArgumentNullException("You must add a script to execute.");

            Assembly thisAssembly = Assembly.GetCallingAssembly();

            MySqlConnection connMySql = null;
            try {
                connMySql = new MySqlConnection(ConnectionString);
                foreach (string file in ScriptsFiles) {
                    string result = string.Empty;
                    using (Stream stream = thisAssembly.GetManifestResourceStream(file)) {
                        using (StreamReader reader = new StreamReader(stream)) {
                            result = reader.ReadToEnd();
                        }
                    }

                    MySqlScript script = new MySqlScript(connMySql, result);
                    script.Delimiter = "$$";
                    script.Execute();
                }

            } catch (MySqlException ex) {
                throw new Exception("Problems with the database sorry...", ex);
            } catch (Exception ex) {
                throw;
            } finally {
                connMySql.Close();
            }

            //sql server
            //FileInfo file = new FileInfo("C:\\myscript.sql");
            //string script = file.OpenText().ReadToEnd();
            //SqlConnection conn = new SqlConnection(sqlConnectionString);
            //Server server = new Server(new ServerConnection(conn));
            //server.ConnectionContext.ExecuteNonQuery(script);
        }
开发者ID:jplindgren,项目名称:SqlScriptExecutor,代码行数:41,代码来源:MysqlScriptExecutor.cs


示例17: initiateDB

 private void initiateDB()
 {
     try
     {
         mysql_connection = new MySqlConnection(connectionString);
         mysql_connection.Open();
         //use the database created and then execute sql scripts to create table and populate with some sample data
         string sqlStatement = "USE " + mysqldbname + ";";
         MySqlCommand cmd = new MySqlCommand(sqlStatement, mysql_connection);
         cmd.ExecuteNonQuery();
         MySqlScript script1 = new MySqlScript(mysql_connection, File.ReadAllText("sql-scripts/create-schema.sql"));
         script1.Delimiter = "$$";
         script1.Execute();
         MySqlScript script2 = new MySqlScript(mysql_connection, File.ReadAllText("sql-scripts/insert-towns.sql"));
         script2.Delimiter = "$$";
         script2.Execute();
     }
     catch (MySqlException ex)
     {
     }
 }
开发者ID:sacooper-pivotal,项目名称:cf-towns-dotnet,代码行数:21,代码来源:Default.aspx.cs


示例18: DbCreateDatabase

        protected override void DbCreateDatabase(DbConnection connection, int? commandTimeout, StoreItemCollection storeItemCollection)
        {
            if (connection == null)
                throw new ArgumentNullException("connection");
            MySqlConnection conn = connection as MySqlConnection;
            if (conn == null)
                throw new ArgumentException(Resources.ConnectionMustBeOfTypeMySqlConnection, "connection");

            string query = DbCreateDatabaseScript(null, storeItemCollection);

            using (MySqlConnection c = new MySqlConnection())
            {
                MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder(conn.ConnectionString);
                string dbName = sb.Database;
                sb.Database = "mysql";
                c.ConnectionString = sb.ConnectionString;
                c.Open();

                string fullQuery = String.Format("CREATE DATABASE `{0}`; USE `{0}`; {1}", dbName, query);
                MySqlScript s = new MySqlScript(c, fullQuery);
                s.Execute();
            }
        }
开发者ID:elevate,项目名称:mysqlconnector-.net,代码行数:23,代码来源:EF4ProviderServices.cs


示例19: Create

        private static void Create(string changesetPath, string host, string port, string database, string username, string password, string definer)
        {
            MySqlConnection conn = null;

            string createDb = "SET NET_READ_TIMEOUT = 1200;DROP DATABASE IF EXISTS " + database + ";" +
                                "CREATE DATABASE " + database + " DEFAULT CHARACTER SET utf8;" +
                                "USE " + database + ";";
            try
            {
                Console.Out.Write("Creating initial database from 00.00.00.sql ...");
                StreamReader streamReader = new StreamReader(changesetPath + "00.00.00.sql", Encoding.UTF8, false);
                string sql = createDb + streamReader.ReadToEnd();
                streamReader.Close();

                sql = Regex.Replace(sql, "DEFINER=`[^`]+`@`[^`]+`", "DEFINER=" + definer);     // replace definer

                conn = new MySqlConnection(string.Format(MYSQL_CONNECTION_STR, host, username, password, port));
                conn.Open();
                MySqlScript script = new MySqlScript(conn, sql);
                script.Error += new MySqlScriptErrorEventHandler(ScriptErrorHandler);
                script.StatementExecuted += new MySqlStatementExecutedEventHandler(ScriptStatementExecutedHandler);
                script.Execute();
            }
            catch (SQLExecuteException)
            {
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Oops!!!!\n" + e.Message);
            }
            finally
            {
                if (conn != null && conn.State != ConnectionState.Closed)
                    conn.Close();
            }
        }
开发者ID:romovs,项目名称:mysv,代码行数:36,代码来源:Program.cs


示例20: OpenConnection

        private MySql.Data.MySqlClient.MySqlConnection OpenConnection(string username, string password) {
            string connString = "server=" + Properties.Settings.Default.db_server + ";"
                                + "uid=" + username + ";"
                                + "pwd=" + password + ";"
                                + "; port=5715; database=inventralalab;";

            try {
                connection = new MySql.Data.MySqlClient.MySqlConnection();
                connection.ConnectionString = connString;
                connection.Open();
                Properties.Settings.Default.Save();
                string[] files = Directory.GetFiles(System.AppDomain.CurrentDomain.BaseDirectory + "../../db/tables");
                foreach (string file in files) {
                    MySqlScript script = new MySqlScript(connection, File.ReadAllText(file));
                    script.Execute();
                }
                
                return connection;
            }
            catch (MySql.Data.MySqlClient.MySqlException ex) {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
开发者ID:squilliams,项目名称:inventralalab,代码行数:24,代码来源:Connection.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MySqlClient.MySqlStream类代码示例发布时间:2022-05-26
下一篇:
C# MySqlClient.MySqlSchemaCollection类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap