本文整理汇总了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;
}
示例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();
}
示例3: UpgrateSQLServerCe
public void UpgrateSQLServerCe()
{
SqlCeEngine engine = new SqlCeEngine(getConnectionString());
// https://msdn.microsoft.com/en-us/library/bb896160.aspx
engine.Upgrade(getConnectionString());
}
示例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;
}
}
示例5: PrepareEngine
public override void PrepareEngine(string connectionString, DbConnection connection)
{
try {
connection.Open();
}
catch {
SqlCeEngine e = new SqlCeEngine(connectionString);
e.Upgrade();
}
finally
{
connection.Close();
}
}
示例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();
}
示例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;
}
}
示例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();
}
}
示例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();
}
}
示例10: Upgrade
public static void Upgrade()
{
System.Data.SqlServerCe.SqlCeEngine engine = new SqlCeEngine("Data Source = 'Database.sdf'");
engine.Upgrade();
}
示例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!");
}
}
示例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;
}
示例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;
}
}
示例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;
}