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


C# SqlCeEngine.Upgrade方法代码示例

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


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

示例1: ExecuteSqlQuery

        public static DataTable ExecuteSqlQuery(string query, params SqlCeParameter[] sqlParams)
        {
            var dt = new DataTable();

            using (var conn = new SqlCeConnection(connStr))
            using (var cmd = new SqlCeCommand(query, conn))
            {
                try
                {
                    SqlCeEngine engine = new SqlCeEngine(conn.ConnectionString);
                    engine.Upgrade(conn.ConnectionString);
                }
                catch
                {
                }

                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddRange(sqlParams);

                conn.Open();
                dt.Load(cmd.ExecuteReader());
            }

            return dt;
        }
开发者ID:WakeDown,项目名称:ServiceCollector,代码行数:25,代码来源:Db.cs

示例2: Form1_Load

        private void Form1_Load(object sender, EventArgs e)
        {
            string cs = GetConnectionString();

            //need to upgrade to sql engine v4.0?
            if (!IsV40Installed())
            {
                SqlCeEngine engine = new SqlCeEngine(cs);
                engine.Upgrade();
            }

            //open connection
            SqlCeConnection sc = new SqlCeConnection(cs);

            //query customers
            string sql = "SELECT * FROM Customers";
            SqlCeCommand cmd = new SqlCeCommand(sql, sc);

            //create grid
            SqlCeDataAdapter sda = new SqlCeDataAdapter(cmd);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            dataGridView1.DataSource = dt;
            dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);

            //close connection
            sc.Close();
        }
开发者ID:quidmonkey,项目名称:SimpleCSharpDatabaseDemo,代码行数:28,代码来源:Form1.cs

示例3: UpgrateSQLServerCe

        public void UpgrateSQLServerCe()
        {
            SqlCeEngine engine = new SqlCeEngine(getConnectionString());

            // https://msdn.microsoft.com/en-us/library/bb896160.aspx

            engine.Upgrade(getConnectionString());
        }
开发者ID:rid50,项目名称:GrabImage,代码行数:8,代码来源:DBUtil.cs

示例4: Upgrade

 private void Upgrade()
 {
     try
     {
         const string connectionString = @"Data Source=App_Data\tests.sdf";
         var ce = new SqlCeEngine(connectionString);
         ce.Upgrade(connectionString);
     }
     catch (Exception)
     {
         // throw;
     }
 }
开发者ID:abithyzis,项目名称:Loquacious-NH,代码行数:13,代码来源:NHibernateSpecification.cs

示例5: PrepareEngine

 public override void PrepareEngine(string connectionString, DbConnection connection)
 {
     try {
         connection.Open();
     }
     catch {
         SqlCeEngine e = new SqlCeEngine(connectionString);
         e.Upgrade();
     }
     finally
     {
         connection.Close();
     }
 }
开发者ID:pedro-ramirez-suarez,项目名称:needletailtools,代码行数:14,代码来源:SqlServerCeEngine.cs

示例6: MainWindow

 public MainWindow()
 {
     InitializeComponent();
       SqlCeConnection connection = new SqlCeConnection("Data Source=Panic.sdf");
       // Upgrade the database if required
       SqlCeEngine engine = new SqlCeEngine(connection.ConnectionString);
       engine.Upgrade();
       siteRepository = new SiteSQL(connection);
       linkRepository = new LinkSQL(connection);
       hardwareRepository = new HardwareSQL(connection);
       graphVisualiser.InitialiseRepository(siteRepository, linkRepository);
       dataConfiguration.InitialiseRepository(siteRepository, linkRepository, hardwareRepository);
       graphVisualiser.Refresh();
 }
开发者ID:stevenandrewcarter,项目名称:Panic,代码行数:14,代码来源:MainWindow.xaml.cs

示例7: LocalDatabase

        public LocalDatabase(string FilePath)
            : base()
        {
            try
            {
                string fileName = Path.Combine(FilePath, "caselist.sdf");               

                connectionString = string.Format("Data Source=\"{0}\"", fileName);

                SqlCeEngine en = new SqlCeEngine(connectionString);

                if (!File.Exists(fileName))
                {                    
                    en.CreateDatabase();
                }

                m_connection = new SqlCeConnection();
                m_connection.ConnectionString = connectionString;

                if (m_connection.State == System.Data.ConnectionState.Closed)
                {
                    try
                    {
                        m_connection.Open();
                    }
                    catch (SqlCeInvalidDatabaseFormatException)
                    {
                        en.Upgrade();
                        m_connection.Open();
                    }                  
                }

                SqlCeCommand SelectTableCommand = new SqlCeCommand();
                SelectTableCommand.CommandText = QuerySelectRowString;
                SelectTableCommand.Connection = m_connection;

                m_adapter = new SqlCeDataAdapter((SqlCeCommand)SelectTableCommand);

                // Create the DbCommandBuilder.
                m_builder = new SqlCeCommandBuilder();
                m_builder.DataAdapter = m_adapter;

                m_adapter.SelectCommand = SelectTableCommand;                
            }
            catch
            {
                throw;
            }
        }
开发者ID:BdGL3,项目名称:CXPortal,代码行数:49,代码来源:LocalDatabase.cs

示例8: UpgradeTo40

        public void UpgradeTo40(string connectionString)
        {
            string filename;
            using (SqlCeConnection conn = new SqlCeConnection(connectionString))
            {
                filename = conn.Database;
            }
            if (filename.Contains("|DataDirectory|"))
                throw new ApplicationException("DataDirectory macro not supported for upgrade");

            SQLCEVersion fileversion = DetermineVersion(filename);
            if (fileversion == SQLCEVersion.SQLCE20)
                throw new ApplicationException("Unable to upgrade from 2.0 to 4.0");

            if (SQLCEVersion.SQLCE40 > fileversion)
            {
                SqlCeEngine engine = new SqlCeEngine(connectionString);
                engine.Upgrade();
            }
        }
开发者ID:herohut,项目名称:elab,代码行数:20,代码来源:SqlCeHelper.cs

示例9: ExequteSqlCommand

        public static void ExequteSqlCommand(string command, params SqlCeParameter[] sqlParams)
        {
            using (var conn = new SqlCeConnection(connStr))
            using (var cmd = new SqlCeCommand(command, conn))
            {
                try
                {
                    SqlCeEngine engine = new SqlCeEngine(conn.ConnectionString);
                    engine.Upgrade(conn.ConnectionString);
                }
                catch
                {
                }

                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddRange(sqlParams);

                conn.Open();
                cmd.ExecuteReader();
            }
        }
开发者ID:WakeDown,项目名称:ServiceCollector,代码行数:21,代码来源:Db.cs

示例10: Upgrade

        public static void Upgrade()
        {
            System.Data.SqlServerCe.SqlCeEngine engine = new SqlCeEngine("Data Source = 'Database.sdf'");

            engine.Upgrade();
        }
开发者ID:pawlo57,项目名称:Warsztat,代码行数:6,代码来源:Connect.cs

示例11: CheckUpgrade

 /// <summary>
 /// Tries to establish a connection to the given database. If this fails with a <see cref="SqlCeInvalidDatabaseFormatException"/>, we try
 /// to update the database to current engine version.
 /// </summary>
 /// <param name="engine">Database engine instance to upgrade.</param>
 protected void CheckUpgrade(SqlCeEngine engine)
 {
   try
   {
     using (SqlCeConnection conn = new SqlCeConnection(_connectionString))
     {
       conn.Open();
       conn.Close();
     }
   }
   catch (SqlCeInvalidDatabaseFormatException)
   {
     ServiceRegistration.Get<ILogger>().Warn("Upgrading existing SQL CE database format to v4.0...");
     engine.Upgrade();
     ServiceRegistration.Get<ILogger>().Warn("Upgrade successful!");
   }
 }
开发者ID:chekiI,项目名称:MediaPortal-2,代码行数:22,代码来源:SQLCEDatabase.cs

示例12: CreateConnection

        protected override DbConnection CreateConnection(Type t, string connectionString)
        {
            SqlCeConnection connection = null;
            try
            {
                connection = new SqlCeConnection(connectionString);
                connection.Open();
            }
            catch (System.Data.SqlServerCe.SqlCeInvalidDatabaseFormatException)
            {
                try
                {
                    var engine = new SqlCeEngine(connectionString);
                    engine.Upgrade();

                    try
                    {
                        connection = new SqlCeConnection(connectionString);
                        connection.Open();
                    }
                    catch (System.Exception){}
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine("Attempt on Upgrading SQL CE Database Failed (Reason = \"" + ex.Message + "\")");
                }
            }
            catch (Exception ex) { Console.WriteLine("Unexpected Error Occurred ! Error Details : " + ex.Message); }
            return connection;
        }
开发者ID:sathukorale,项目名称:libDatabaseHelper,代码行数:30,代码来源:ConnectionManager.cs

示例13: ExecuteReader

        public static SqlCeDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText, params SqlCeParameter[] commandParameters)
        {
            if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString");
            SqlCeConnection connection = null;
            try
            {
                connection = new SqlCeConnection(connectionString);
                try
                {
                    connection.Open();
                }
                catch (SqlCeInvalidDatabaseFormatException)
                {
                    using (SqlCeEngine engine = new SqlCeEngine())
                    {
                        engine.Upgrade(connectionString);
                    }

                    connection = new SqlCeConnection(connectionString);
                    connection.Open();

                }

                using (SqlCeCommand command = new SqlCeCommand())
                {
                    PrepareCommand(
                        command,
                        connection,
                        null,
                        commandType,
                        commandText,
                        commandParameters);

                    return command.ExecuteReader(CommandBehavior.CloseConnection);
                }
            }
            catch
            {
                if ((connection != null) && (connection.State == ConnectionState.Open)) { connection.Close(); }
                throw;
            }
        }
开发者ID:saiesh86,项目名称:TravelBlog,代码行数:42,代码来源:SqlHelper.cs

示例14: GetOpenSettingsConnection

 public static SqlCeConnection GetOpenSettingsConnection()
 {
     if (_settingsConn.State != System.Data.ConnectionState.Open)
     {
         try
         {
             _settingsConn.Open();
         }
         catch (SqlCeInvalidDatabaseFormatException)
         {
             SqlCeEngine engine = new SqlCeEngine(_settingsConn.ConnectionString);
             engine.Upgrade();
             _settingsConn.Open();
         }
     }
     return _settingsConn;
 }
开发者ID:neurocache,项目名称:ilSFV,代码行数:17,代码来源:Program.cs


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